- Home /
Question by
Tristion · Apr 29, 2016 at 11:54 AM ·
unity 5gameobjecttrigger
Space Shooter Tutorial 5.3 first Asteroid being destroyed
I am learning Unity and have completed the Space Shooter Tutorial for 5.3. I have a problem where the very first Asteroid is being destroyed when it spawns, all the rest seem to be fine. The Asteroid gets destroyed and the Explosion Audio goes off and the count increments to 10. I am thinking its something to do with DestroyByContact script but am unable to pin point the problem. Any tips on what the issue might be would be great. Great Tutorial btw, lot of fun to do.
This is the DestroyByContact script:
void Start()
{
GameObject gameControllerObject = GameObject.FindWithTag("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent<GameController>();
}
if (gameController == null)
{
Debug.Log("Cannot find 'GameController' script");
}
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Boundary")
{
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);
}
Comment