- Home /
destroy instantiated game object on collision with another game object
hi friends,i cam across a scenario where instantiated game object must be destroyed when collided with another gameobject.i.e.,missile must be destroyed if it hits particular object. i used array for instantiated missiles.i applied below collision script to the missile:
void OnTriggerEnter (Collider other)
{
if(other.collider.gameObject.tag == "tanker_body" )
{
Destroy(this.gameObject);
}
}
Please use the 101-010 button to format code so we can read it - I've done it for you this time.
am sorry Loius thanks for the tip.am new to forum.thanku
Answer by Loius · Nov 28, 2012 at 06:55 AM
You need to have a rigidbody on both colliders (this and the ship). Make sure your tanker body is tagged properly. If you have more trouble, use Debug.Log(other.name) in that function to determine if the object is hitting anything at all.
hey Loius thanks for ur suggestion.i achieved the above functionality by using arrays for the instantiated game object and i destroyed the instantiated game object by giving the index which increments on a trigger function.thanks to all