Photon.instansiate (how do i get objects to instantiate at my SpawnPoints?)
Options
hey gang, a simple problem I'm using:
Should be very simple thing, yet it spawns every fighter at the center of my map rather then at their spawn points.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpawnFighter : Photon.MonoBehaviour { // Use this for initialization void Start () { if (PhotonNetwork.isMasterClient) { PhotonNetwork.Instantiate ("T2Fighter", transform.position, transform.rotation, 0); } } }
Should be very simple thing, yet it spawns every fighter at the center of my map rather then at their spawn points.
0
Comments
-
Hi @ZakAttack247,
You are using the transform of the SpawnFighter as a spawn point.
You should have the spawn points available from script and probably assigned from the editor and then you should choose which spawn point for each player, in the example below I use random index:using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpawnFighter : Photon.MonoBehaviour { [SerializeField] private Transform[] spawnPoints; // drag and drop in Inspector // Use this for initialization void Start () { if (PhotonNetwork.isMasterClient) { int index = Random.Range(0, spawnPoints.Length); spawnPointTransform = spawnPoints[index]; PhotonNetwork.Instantiate ("T2Fighter", spawnPointTransform.position, spawnPointTransform.rotation, 0); } } }
0 -
[SerializeField]
private Transform[] spawnPoints; // drag and drop in Inspector
private Transform spawnPointTransform;
thanks man0