Question by
joshua40698 · Mar 26, 2016 at 05:07 PM ·
null reference exception
NullReferenceException in 20 says " Object Reference not set to instance of object Please help
using UnityEngine;
using System.Collections;
public class PlayerDeath : MonoBehaviour {
public GameManager TheGameManager;
void Start () {
TheGameManager = GetComponent<GameManager> ();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D other){
if(other.name == "Player")
{
TheGameManager.RespawnPlayer();
}
}
}
Comment
Answer by Downstream · Mar 26, 2016 at 08:02 PM
Do you have TheGameManager component on the same object? GetComponent() gets from the same gameobject this script is attached to.
Your answer

Follow this Question
Related Questions
NullReferenceException: Object reference not ... ( Assistance please ) 2 Answers
NullReferenceException: Object reference not set to an instance of an object 3 Answers
Custom class instance always return null 1 Answer
null reference help. i fundamentally dont understand. 1 Answer
why does a line renderer cause a nullreference excepetion? 0 Answers