简体   繁体   中英

Photon in Unity is instantiating two players for seemingly no reason

I've been trying to implement multiplayer in my game for the past day now with little success. First UNET had no native way to sync scale between clients and now after I've changed over to Photon I've got another problem I can't seem to fix and it is happening for seemingly no reason at all.

When I click play, I wait for a bit and two players are instantiated. I only have one Unity instance open, only one instance of my script that instantiates it and I can't think of anything else in my current testing area that would cause two players to spawn.

Here's the code inside my 'NetworkManager'

const string VERS = "V.0.1";
public GameObject player;
void Start () {
    PhotonNetwork.ConnectUsingSettings(VERS);

}

void OnJoinedLobby()
{
    RoomOptions roomOptions = new RoomOptions() {IsVisible=false,MaxPlayers=1};
    PhotonNetwork.JoinOrCreateRoom("Room1", roomOptions, TypedLobby.Default);

}

void OnJoinedRoom()
{
    PhotonNetwork.Instantiate("Player",GameObject.Find("SpawnPoint").transform.position,Quaternion.Euler(0,0,0),0);
}

void Update () {

}

I've made it specifically look for 'Player' instead of using the GameObject variable's transform name incase it was finding two prefabs for some strange reason but it wasn't. A print statement shows that OnJoinedRoom is being called twice which I don't understand why.

I have auto-join lobby switched to true in the photon settings object that's created when you start up. Setting it to false results in nothing being instantiated.

原来,我还将该脚本附加到另一个名为SpawnPoint的空容器中,并且没有意识到!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM