Hello,
I am working on a real time multiplayer project with Unity 3D. It is 2D game. I change the view of the player by changing it’s sprite. But when i change the sprite of the local player and when i join the lobby, and when i connect that lobby from different device, i can’t see the change of the other player. So the question is, how can i update the changed view of the player? Or how can i update the other player’s change from local device?
I solved the problem by changing my script from this:
public static int playerViewInt;
public GameObject mainOutline;
public GameObject top;
public Sprite[] outlineSprite;
public Sprite[] topSprite;
public void startChangeView()
{
playerViewInt = PlayerPrefs.GetInt("PlayerViewINT");
PhotonView photonView = PhotonView.Get(this);
photonView.RPC("changeView", PhotonTargets.All, null);
changeView();
}
[RPC]
public void changeView()
{
if(playerViewInt == 0)
{
mainOutline.transform.GetComponent().sprite = outlineSprite[0];
top.transform.GetComponent().sprite = topSprite[0];
}
if(playerViewInt == 1)
{
mainOutline.transform.GetComponent().sprite = outlineSprite[1];
top.transform.GetComponent().sprite = topSprite[1];
}
if(playerViewInt == 2)
{
mainOutline.transform.GetComponent().sprite = outlineSprite[2];
top.transform.GetComponent().sprite = topSprite[2];
}
if(playerViewInt == 3)
{
mainOutline.transform.GetComponent().sprite = outlineSprite[3];
top.transform.GetComponent().sprite = topSprite[3];
}
}
TO:
public static int playerViewInt;
public GameObject mainOutline;
public GameObject top;
public Sprite[] outlineSprite;
public Sprite[] topSprite;
public void startChangeView()
{
playerViewInt = PlayerPrefs.GetInt("PlayerViewINT");
changeView();
}
public void changeView()
{
if (photonView.isMine)
{
if(playerViewInt == 0)
{
photonView.RPC("changeSprite0", PhotonTargets.AllBuffered, null);
PlayerPrefs.SetInt("PlayerViewINT", playerViewInt);
}
if(playerViewInt == 1)
{
photonView.RPC("changeSprite1", PhotonTargets.AllBuffered, null);
PlayerPrefs.SetInt("PlayerViewINT", playerViewInt);
}
if(playerViewInt == 2)
{
photonView.RPC("changeSprite2", PhotonTargets.AllBuffered, null);
PlayerPrefs.SetInt("PlayerViewINT", playerViewInt);
}
if(playerViewInt == 3)
{
photonView.RPC("changeSprite3", PhotonTargets.AllBuffered, null);
PlayerPrefs.SetInt("PlayerViewINT", playerViewInt);
}
}
else
{
return;
}
}
[RPC] public void changeSprite0()
{
mainOutline.transform.GetComponent().sprite = outlineSprite[0];
top.transform.GetComponent().sprite = topSprite[0];
}
[RPC] public void changeSprite1()
{
mainOutline.transform.GetComponent().sprite = outlineSprite[1];
top.transform.GetComponent().sprite = topSprite[1];
}
[RPC] public void changeSprite2()
{
mainOutline.transform.GetComponent().sprite = outlineSprite[2];
top.transform.GetComponent().sprite = topSprite[2];
}
[RPC] public void changeSprite3()
{
mainOutline.transform.GetComponent().sprite = outlineSprite[3];
top.transform.GetComponent().sprite = topSprite[3];
}
But right now, i have another problem. When i start local and second device for the first time by clicking on start multiplayer button, the player which is in second device, disappears after the players connect to main game screen. I leave the room after that and start an another multiplayer game for both device and after that it seems on the screen. What could be the problem on the first time multiplayer game set?