Search code examples
c#unity-game-enginenetwork-programmingmultiplayer

Unity: Instantiate Object at position of another object


I may be going about this the wrong way but I want to have the playerPrefab spawn at the object playerSpawn. Currently it spawns at some other location.

var made = Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);

made.GetComponent(playerMove).playerName = playerName;

Solution

  • Object.Instantiate
    public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);

    You can specify the "spawn" position by using the second parameter, position.

    Same is true for Network.Instantiate.