Quantcast
Channel: Questions in topic: "spawn points"
Viewing all articles
Browse latest Browse all 102

Accessing different spawn points

$
0
0
So I have my spawning code for the player working how I need it to, but my problem is I need to be able to access several different spawn points across the game in different scenes, and my code only allows me to use one spawn point. Here is the code that places the player at the spawn point: using UnityEngine; using System.Collections; public class SpawnAtSpawnPoint : MonoBehaviour { GameObject spawnPoint; public string SpawnPointName; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } public void OnLevelWasLoaded() { spawnPoint = GameObject.FindWithTag ("SpawnPoint"); if (spawnPoint.name == SpawnPointName) { transform.position = spawnPoint.transform.position; } } } So what's going on is it can only place me at the one spawn point specified by SpawnPointName. I've tried to have it access the spawn point name given in the door script, but upon testing if it worked by using print it just said "Null," so I'm pretty sure it didn't work. I have both the player and the camera set up with DontDestroyOnLoad. If it'll help, here's the script I have attached to the doors: using UnityEngine; using System.Collections; public class DoorScript : MonoBehaviour { public string NextScene; public string SpawnPointName; //public Transform Player; //GameObject spawnPoint; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnTriggerStay (Collider other) { if (other.gameObject.tag == "Player") { if (Input.GetButton ("Interact")) { Application.LoadLevel (NextScene); GetComponent().OnLevelWasLoaded(); } } } }

Viewing all articles
Browse latest Browse all 102

Trending Articles