Hello everyone.
I’ll cut straight to the point.
I created a session. I’m able to connect and spawn players and move around but I’m having a bit of a problem.
Players are white circles.
I’ve created a button that ‘spawns’ players into the session.
I want the player to type a name, this name will be assigned to a Text mesh so it gets displayed overhead.
I also want the player’s sprite to be randomly colored to tell them apart.
I’m not being able to pass any of these values to the other players. Every player is white and I can only display my own name. Other players are displayed as ‘Player(Clone)’
Here’s some code:
SpawnPlayer is part of the networkManager.(not attached to the player).
///Happens when you press the spawn button.
void SpawnPlayer(){
_playerInGameName = GUI.TextField (new Rect (Screen.width / 2, Screen.height/2 - 50, 200, 20), _playerInGameName, 25);
//Color randomizer.
_playerColorR = Random.Range (0.0f,1.0f);
_playerColorG = Random.Range (0.0f,1.0f);
_playerColorB = Random.Range (0.0f,1.0f);
_thisPlayer = PhotonNetwork.Instantiate(_playerPrefabName,new Vector3(0f,0f,0f),Quaternion.identity,0);
_thisPlayer.name = _playerInGameName;
_thisPlayer.GetComponent<SpriteRenderer>().color = new Color(_playerColorR,_playerColorG,_playerColorB,_playerColorA);
_thisPlayer.GetComponent<PhotonView>().owner.name = _thisPlayer.name;
}
Here’s part of a script attached to player.
Net_Player.cs
void ToggleNameMesh(){
_playerInGameNameMesh = this.transform.FindChild("playerName").gameObject;
_playerInGameNameMesh.SetActive(true);
_playerInGameNameMesh.GetComponent<TextMesh>().text = this.GetComponent<PhotonView>().owner.name;
}
As you can see, the nameMesh is a child gameObject of the Player.
A)What is the proper way to pass names/values to the OTHER NETWORK Players.(in this case the random colors and the names)
B)If I wanted to do the paint the player function. What would be the most efficient way?(Lets say with a function called paintMySprite(float R,f G,f B,f A);