How to I get a random player
iamE
✭
I want to get some random players in a room at the start of a new round, but I don't know about to pick random players. Can someone help, please?
0
Comments
-
One of forum search result for 'random player': http://forum.exitgames.com/viewtopic.php?f=17&t=5365&p=20399&hilit=random+player#p20399
Is it what you are looking for?0 -
Please do the Marco Polo Tutorial. It uses a very simple random matchmaking workflow.
http://doc.exitgames.com/en/pun/current ... marco-polo0 -
vadim wrote:One of forum search result for 'random player': http://forum.exitgames.com/viewtopic.php?f=17&t=5365&p=20399&hilit=random+player#p20399
Is it what you are looking for?0 -
Then asking for clarification in old post is better option.
Use [] to take array element with given index:
int i = random(PhotonNetwork.playerList.Length)
PhotonPlayer randomPlayer = PhotonNetwork.playerList
Where 'random' is function of your choice returning random integer from [0, PhotonNetwork.playerList.Length) range0 -
vadim wrote:Then asking for clarification in old post is better option.
Use [] to take array element with given index:
int i = random(PhotonNetwork.playerList.Length)
PhotonPlayer randomPlayer = PhotonNetwork.playerList
Where 'random' is function of your choice returning random integer from [0, PhotonNetwork.playerList.Length) range0 -
This is a simple example of one way to accomplish the task.
using System.Collections.Generic;public List<string> PlayerList = new List<string>();
We can call PlayerConnectedvoid OnPhotonPlayerConnected(){ if (!PlayerList.Contains (PhotonNetwork.playerName)) { PlayerList.Add (PhotonNetwork.playerName); } }
Next We Need A Pick Random Method to Invokevoid TagRandomPlayer(){ int PlayerListRange = PlayerList.Count; System.Random Rand = new System.Random (); int RandomPick = Rand.Next (0, PlayerListRange); string TaggedPlayer = PlayerList [RandomPick]; }
0 -
CoreWorkNode wrote:This is a simple example of one way to accomplish the task.
using System.Collections.Generic;public List<string> PlayerList = new List<string>();
We can call PlayerConnectedvoid OnPhotonPlayerConnected(){ if (!PlayerList.Contains (PhotonNetwork.playerName)) { PlayerList.Add (PhotonNetwork.playerName); } }
Next We Need A Pick Random Method to Invokevoid TagRandomPlayer(){ int PlayerListRange = PlayerList.Count; System.Random Rand = new System.Random (); int RandomPick = Rand.Next (0, PlayerListRange); string TaggedPlayer = PlayerList [RandomPick]; }
0 -
Make sure you add
using System.Collections.Generic;using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ClassName : MonoBehaviour {}0 -
CoreWorkNode wrote:Make sure you add
using System.Collections.Generic;using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ClassName : MonoBehaviour {}0 -
iamE wrote:How do I apply the tag to the picked player? Do I turn the String TaggedPlayer into a gameObject instead a string so I can use .tag or will that not work? Ty for the help.
This is where we start to leave scope of the original problem.
string TaggedPlayer, is your Random player you wanted. Now we need to do something with it, What that is only you know.
you could maybe cast something like this.
.GetComponent<PhotonView> ().owner & Match that with TaggedPlayer
At that point, you could invoke the method you want.
i.e (Mark PlayerObject)0 -
CoreWorkNode wrote:iamE wrote:How do I apply the tag to the picked player? Do I turn the String TaggedPlayer into a gameObject instead a string so I can use .tag or will that not work? Ty for the help.
This is where we start to leave scope of the original problem.
string TaggedPlayer, is your Random player you wanted. Now we need to do something with it, What that is only you know.
you could maybe cast something like this.
.GetComponent<PhotonView> ().owner & Match that with TaggedPlayer
At that point, you could invoke the method you want.
i.e (Mark PlayerObject)0 -
CoreWorkNode wrote:iamE wrote:How do I apply the tag to the picked player? Do I turn the String TaggedPlayer into a gameObject instead a string so I can use .tag or will that not work? Ty for the help.
This is where we start to leave scope of the original problem.
string TaggedPlayer, is your Random player you wanted. Now we need to do something with it, What that is only you know.
you could maybe cast something like this.
.GetComponent<PhotonView> ().owner & Match that with TaggedPlayer
At that point, you could invoke the method you want.
i.e (Mark PlayerObject)0 -
CoreWorkNode wrote:iamE wrote:How do I apply the tag to the picked player? Do I turn the String TaggedPlayer into a gameObject instead a string so I can use .tag or will that not work? Ty for the help.
This is where we start to leave scope of the original problem.
string TaggedPlayer, is your Random player you wanted. Now we need to do something with it, What that is only you know.
you could maybe cast something like this.
.GetComponent<PhotonView> ().owner & Match that with TaggedPlayer
At that point, you could invoke the method you want.
i.e (Mark PlayerObject)0