I have an object tagged ‘red’ and an object tagged ‘orange’ that both have a similar setup. When a cube, which has a rigidbody, collides with the red object it destroys it using Destroy (other.gameObject); but when it collides with the orange object it doesn’t. I gave the orange object the ‘red’ tag and the cube destroys it fine. The code telling the code to destroy the red and orange objects is identical.
-
edit Ok I should also mention that there are 8 different objects that the cube can collide with and all detection is done in a bunch of if else statements. And, most importantly, if I move the line about destroying the orange object higher up the chain of if else statements…it works! What is going on!?!
void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag ("whitewall")) { Destroy (this.gameObject); Destroy (other.gameObject); print ("destroyed by wall"); } else if (other.gameObject.CompareTag ("orangetower")) { Destroy (other.gameObject); } else if (other.gameObject.CompareTag ("redroad")) { Destroy (other.gameObject); } else if (other.gameObject.CompareTag ("yellowroad")) { Destroy (other.gameObject); } else if (other.gameObject.CompareTag ("yellowrheart")) { Destroy (other.gameObject); } else if (other.gameObject.CompareTag ("orangetower")) { Destroy (other.gameObject); } else if (other.gameObject.CompareTag ("blueplant")) { Destroy (other.gameObject); } else if (other.gameObject.CompareTag ("greenplant")) { Destroy (other.gameObject); } else if (other.gameObject.CompareTag ("Player")) { Destroy (other.gameObject); } else if (other.gameObject.CompareTag ("blueplant")) { Destroy (this.gameObject); Instantiate (Resources.Load ("dark") as GameObject, threeUp.position, Quaternion.identity); print ("destroyed by blueplant"); }
}