- Home /
whats wrong....
NullReferenceException: Object reference not set to an instance of an object Done_DestroyByContact.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Done/Done_Scripts/Done_DestroyByContact.cs:42)
Im fallowing along with the space shooter project and i was able to get everything to work. I then brought in my own models and for some reason im getting an error and my objects are not doing what they are suppose to
using UnityEngine;
using System.Collections;
public class Done_DestroyByContact : MonoBehaviour
{
public GameObject explosion;
public GameObject playerExplosion;
public int scoreValue;
private Done_GameController gameController;
void Start ()
{
GameObject gameControllerObject = GameObject.FindGameObjectWithTag ("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent <Done_GameController>();
}
if (gameController == null)
{
Debug.Log ("Cannot find 'GameController' script");
}
}
void OnTriggerEnter (Collider other)
{
if (other.tag == "Boundary" || other.tag == "Enemy")
{
return;
}
if (explosion != null)
{
Instantiate(explosion, transform.position, transform.rotation);
}
if (other.tag == "Player")
{
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
gameController.GameOver();
}
gameController.AddScore(scoreValue);
Destroy (other.gameObject);
Destroy (gameObject);
}
}
I assume that the Debug Log does not print "Cannot find 'GameController' script" ?
Does Done_GameController have a public .AddScore() method?
I had the wrong script selected.... I needed "GameController" script and i had "Done_GameController" script selected. This is strange because i didn't create the Done_GameController script. problem solved.
Thanks for your response.
"whats wrong..." must be the most descriptive title I've ever seen. Please title your questions appropriately.
Your answer
Follow this Question
Related Questions
OnTriggerEnter Not working in sample project 2 Answers
OnTriggerEnter not working as intended 1 Answer
Non-Rigidbody equivalent to OnTriggerEnter? 2 Answers
Destroy Gameobject without BoxCollider2D 2 Answers