- Home /
Question by
Gatau · Feb 21, 2015 at 11:33 PM ·
cameranetworkingphoton
camera only sticks to the master client
Hi, I am using the Photon networking API and my problem is that only the master client (host) gets the camera following his character.
This is how I do it:
Instantiate player:
private void PlayerInitializer()
{
GameObject thisPlayer;
currentCharacter = Camera.main.GetComponent<PlayerCreator>().currentCharacter;
if (PhotonNetwork.connectionState == ConnectionState.Disconnected)
{
thisPlayer = Instantiate(player, new Vector2(0, 0), Quaternion.identity) as GameObject; // instantiate player object
}
else
{
thisPlayer = PhotonNetwork.Instantiate(player.name, new Vector3(0, 0), Quaternion.identity, 0) as GameObject;
}
thisPlayer.tag = "Player";
thisPlayer.name = "Player";
Camera.main.GetComponent<CameraBehaviour>().GetMyPlayer();
}
Then we call GetMyPlayer
on the camera to get the player that belongs to me:
public void GetMyPlayer()
{
players = GameObject.FindGameObjectsWithTag("Player");
GameObject result = null;
foreach (GameObject player in players)
{
if (PhotonNetwork.connectionState == ConnectionState.Disconnected || photonView.isMine)
{
result = player;
break;
}
}
this.player = result;
}
And then we Update the camera to follow the player:
void Update()
{
if(player != null)
{
transform.position = new Vector3(player.transform.position.x, player.transform.position.y, -100);
}
}
The client client does not get his camera attached to any player while the master client does.
Comment