Photon.instansiate (how do i get objects to instantiate at my SpawnPoints?)

Options
ZakAttack247
edited February 2017 in Any Topic & Chat
hey gang, a simple problem I'm using:
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.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    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);
    		}
    	}
    }
  • ZakAttack247
    edited February 2017
    Options
    [SerializeField]
    private Transform[] spawnPoints; // drag and drop in Inspector
    private Transform spawnPointTransform;
    :D thanks man