- Home /
Question by
quocchi22101262 · Jul 22, 2016 at 05:18 PM ·
errorerror messageclass objectclass instance
Why have error: NullReferenceException: Object reference not set to an instance of an object
public class GamePlayManager : MonoBehaviour {
public void BirdDiedShowPanel(){
pausePanel.SetActive (true);
scoreText.gameObject.SetActive (false);
gameOverUI.gameObject.SetActive (true);
resumeGameButton.onClick.RemoveAllListeners ();
resumeGameButton.onClick.AddListener(()=>RestartGameButton());
}
}
public class BlueBirdScript : MonoBehaviour {
void OnCollisionEnter2D(Collision2D target){
GamePlayManager t = new GamePlayManager();
if (target.gameObject.tag == "Ground" || target.gameObject.tag == "Pipe") {
if (birdIsAlive) {
birdIsAlive = false;
anim.SetTrigger ("Died");
audioSource.PlayOneShot (diedClip);
GamePlayManager.instance.BirdDiedShowPanel();
t.BirdDiedShowPanel ();
}
}
}
why t.BirdDiedShowPanel error (line 22) ???, I don't understand, please explain it
Comment
Answer by Jessespike · Jul 22, 2016 at 05:40 PM
Put GamePlayManager on a GameObject in the scene and find it. You cannot create and allocate a new component that is not attached to anything.
//GamePlayManager t = new GamePlayManager();
GamePlayManager t = FindObjectOfType<GamePlayManager>();
Your answer
Follow this Question
Related Questions
Error, I have no idea why :( 2 Answers
Was gameObject.GetChild(childsName); a thing? 2 Answers
Monodevelop Fatal Error 0 Answers
NullReferenceException on empty project because of ScriptCompilerBase 0 Answers