Search Unity

Photon Instantiate prefabs in different positions

Discussion in 'Scripting' started by Batuhan13, May 7, 2021.

  1. Batuhan13

    Batuhan13

    Joined:
    Apr 9, 2017
    Posts:
    117
    Hi mates I am trying to instantiate prefabs in different rooms first prefab will be in first room and second prefab will be in second room and finally third prefab will be in first room again it is continuing like this. I created a lobby and added a start button which run this lines
    Code (CSharp):
    1. public void OnStartGameButtonClicked()
    2.     {
    3.         if(PhotonNetwork.IsMasterClient)
    4.         {
    5.             PhotonNetwork.LoadLevel("GameScene");
    6.         }
    7.     }
    For instantiating I added a GameManager.cs to my level scene in a empty gameobject and I added these lines
    Code (CSharp):
    1. void Start()
    2.     {
    3.         if (PhotonNetwork.IsConnectedAndReady)
    4.         {
    5.             if (_playerPrefab != null)
    6.             {
    7.                 if (PhotonNetwork.CurrentRoom.PlayerCount % 2 == 0)
    8.                 {
    9.                     PhotonNetwork.Instantiate(_playerPrefab.name, _spawnPoints[0].transform.position, Quaternion.identity);
    10.                 }
    11.                 else
    12.                 {
    13.                     PhotonNetwork.Instantiate(_playerPrefab.name, _spawnPoints[1].transform.position, Quaternion.identity);
    14.                 }
    15.             }
    16.         }
    17.     }
    But unfortunately its spawning them in a same position. Do you know what should I do for solve this problem? Thanks and have a great day!!:D