Sync Objects other than Players

Options
Hello,

We have been making our first multiplayer game which is a shooting Game(FPS) using unity and we are having an amazing time working with Photon. :)
we have been able to create room and make the player join the room and have made the players sync across the network.
we have just one query which we would like to ask on this forum regarding networking.

its a two player game and players have to find the animal(one animal in the game) which has spawned in a random location in the game and the first player to shoot(kill) the animal wins.
we would like to know how to handle the animal so there is only one instance of the animal and sync the health, shoot and animations across the network..so the two players see the same thing.
we tried using PhotonNetwork.Instantiate, but it creates two copies of the animal at the same spot..we want to create just one copy of the animal and sync it across.
how to handle this. Do i need to use PhotonNetwork.InstantiateSceneObject for it.
Any suggestions would be of great help. :)

Comments

  • chaozz
    Options
    You are probably instantiating the animal on both players. This will indeed create two animals.

    In PUn one of the players is the master client, and he is the first one that enters the room. You should let him handle the animal.

    if(PhotonNetwork.isMasterClient) PhotonNetwork.InstantiateSceneObject(etc...

    Instantiating a scene object makes sure the animal will not disappear when the master client loses connection.

    Syncing the position of the animal should be done with serializing, like you do with players. In this case you should send data if you're the masterclient, and read the data if you're not.