Trying to Instantiate a array

Options
Hey, i am currently trying to get the following code working, its a array.
gameObj = PhotonNetwork.Instantiate(availableObjects[i], gameObject.transform.position, Quaternion.identity, 0);

Heres the error: No appropriate version of 'PhotonNetwork.Instantiate' for the argument list '(UnityEngine.GameObject, UnityEngine.Vector3, UnityEngine.Quaternion, int)' was found.

Thanks for your help in advance.

Comments

  • vadim
    Options
    Hi,

    String (prefab name) expected as 1st argument of PhotonNetwork.Instantiate. But you pass UnityEngine.GameObject instead.
  • Yes, but how would you instansiate a GameObject array then, or could you?

    Thanks
  • vadim
    Options
    Not quite clear what are you going to do.
    Maybe call PhotonNetwork.Instantiate several times and put results in array?
  • AlignedGames
    Options
    Very late but if anyone needs the answer to this - Photon instantiates with strings, so you need to set up an array of strings.

    Make sure to have all the relevant GameObjects saved in the resources folder for Photon to pull them from there.

    Then you'll just need to enter the names of the GameObjects as string in the inspector by the relevant array values.

    Here's an example of the code :

    public string[] YourGameObjects;

    void Awake()

    {

    PhotonNetwork.Instantiate(YourGameObjects[UnityEngine.Random.Range(0, BlockingInstances.Length)], transform.position, Quaternion.identity);

    }

    }