Reputation: 11
I have a SteamVR Unity project which I'm converting to multiplayer. When another client joins the game, instead of two different players seeing each other, each player has it's own version of the game where he controls all fo the player instances. For example, while one player is connected everything is fine, but when a second player joins, the game just adds another Player prefab which the first player controls as well. I tried replacing the Player with a simple cube and everything seems fine. both the Player and the cube have Photon Transform View and Photon View scripts. I would appreciate any help I can get.
Upvotes: 1
Views: 2300
Reputation: 59
Unity doesn't know if it's multiplayer or not. When you give an input all of the scripts who are waiting for input takes it and behaves accordingly. To solve this basically create another player that doesn't take any input and spawn it for other players.
Upvotes: 1
Reputation: 174
This is a common problem, when you start with PUN. You probably setup a player prefab with network synchronization and instantiate that for each player. All scripts on the instances will act on the local input, which is what you see now. You want two variants of the prefab, for local and remote representation. As it's impractical to always configure two prefabs, instead you build one which initializes itself (in Awake or Start) as local or remote. Your scripts should check the object's PhotonView if it's .isMine or not. This can be done per Component (in each distinct script) or you could add a component which enables/disables the scripts on a GameObject, depending on isMine.
The Basics Tutorial does this, for example.
Upvotes: 2