ok so i have defined a game object variable. and i know how to destroy an object but i need an example script that says something like if collide with this game object then be destroyed
either on the thing that destroys the other
function OnCollisionEnter(collision : Collision) {
Destroy(collision.gameObject);
}
or on the things that are destroyed
function OnCollisionEnter(collision : Collision) {
//if(collision.gameObject.tag == "Destroyer")
Destroy(gameObject);
}
You could attach a collision script to your game object. If your game object is traveling at some rate (its velocity is > 0) then you can do something like:
public class CollisionScript : MonoBehaviour {
private void OnCollisionEnter(Collision collision) {
transform.rigidbody.velocity = Vector3.zero; // stop the moving object
// instantiate an effect
StartCoroutine(CollisionEffect());
}
private IEnumerator CollisionEffect() {
// has the effect stopped?
Destroy(gameObject, 1.5f);
}
}