To give/transfer/obtain some special data (here it is color information) when a player enters the game, you can:
Add dedicated buttons in the launcher UI and connect them to different callbacks:
public void ConnectUser1 () {
//...
Connect () ;
}
public void ConnectUser2 () {
//...
Connect () ;
}
public void ConnectUser3 () {
//...
Connect () ;
}
Give some new attributes to the "PlayerPrefs" that will be used when connecting (in the "Launcher.cs" script):
public void ConnectUser1 () {
PlayerPrefs.SetFloat ("Red", 1.0f) ;
PlayerPrefs.SetFloat ("Green", 0.0f) ;
PlayerPrefs.SetFloat ("Blue", 0.0f) ;
Connect () ;
}
Use them when creating the new users or their interaction tools:
void Start () {
if (photonView.IsMine || ! PhotonNetwork.IsConnected) {
float red = PlayerPrefs.GetFloat ("Red") ;
float green = PlayerPrefs.GetFloat ("Green") ;
float blue = PlayerPrefs.GetFloat ("Blue") ;
colorRenderer.material.color = new Color (red, green, blue) ;
} else {
photonView.RPC ("SendMeTheColor", RpcTarget.Others) ;
PhotonNetwork.SendAllOutgoingCommands () ;
}
}
Add some methods for asking for the attributes and sending them:
[PunRPC]
void SendMeTheColor (PhotonMessageInfo info) {
if (photonView.IsMine || ! PhotonNetwork.IsConnected) {
var c = colorRenderer.material.color ;
Vector3 myVector = new Vector3 (c.r, c.g, c.b) ;
photonView.RPC ("SetTheColor", RpcTarget.All, myVector) ;
PhotonNetwork.SendAllOutgoingCommands () ;
}
}
[PunRPC]
void SetTheColor (Vector3 myVector, PhotonMessageInfo info) {
Color c = new Color (myVector [0], myVector [1], myVector [2]) ;
colorRenderer.material.color = c ;
}
Create one C# script "ColorManager" in order to be able to change the color of any object associated to a user:
Add an attribute to this class:
public Renderer colorRenderer = null ;
Put the 3 previous methods in this class ("Start", "SendMeTheColor", "SetTheColor")
Initialize the "colorRenderer" attribute in the Unity editor with the Photon GameObject you want to change the color
Add the name of the users to their avatars
Let the users choose a dedicated avatar
Let the users choose their location and orientation when they enter the shared world
Announce (by a sound, visually, providing a minimap) each user joining the shared virtual environment
Enable users to ask for help or attention from other users