New to Photon. How can I make sure the players spawn in the right place?

Options

Just picked up Photon today and am looking at spawning my players. There's a spawn for the first player and the second player but I don't know how I can make sure Player 1 spawns at the first spawn and Player 2 spawns at the second.

I saw this code by BlackThornProd which would theoretically work fine because you don't need to check if a spawn is taken. But in my case I probably do and if I try to check that via a script it'll probably be false on the client for the second Player and true on the client for the first Player

Answers

  • Klover
    Options

    public List<GameObject> playerList; //When a player is Instantiated in the scene add them to this list.


    foreach(GameObject otherPlayer in playerList)

    {

    if(transform.position == otherPlayer.transform.position) //If your position is equal to another player's position just send yourself to another spot but to be honest this probably won't happen because Random.Range is typically so vast that it never happens.

    {

    transform.position = new Vector2( Just randomize some coordinates again);

    }

    }