So i’m trying to do a simple Doom-like FPS and i wanted to implement a respawn script.
using UnityEngine;
using System.Collections;
public class Respawn : MonoBehaviour
{
public static Transform[] respawnPoints;
public static Transform player;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
}
public static void respawnAt(int randomPoint)
{
player.position = respawnPoints[randomPoint].position;
}
}
This is what the respawn script looks like.
I want to activate the respawnAt method by entering a Zone
using UnityEngine;
using System.Collections;
public class FallOfMapZone : MonoBehaviour
{
void OnCollisionEnter(Collision col)
{
if(col.gameObject.transform.tag == "Player")
{
Respawn.respawnAt(Random.Range(1, 5));
}
}
}
But for some reason i get an error as soon as i go into the area: “NullReferenceExeption: Object Reference not set to an instance of an object. Respawn.respawnAt(Int32 randomPoint) (at Assets/Scripts/World/Respawn.cs:16)”