Ok so i have my FIRST-PERSON CONTROLLER and i want certain cubes to be destroyed as soon as the controllers collides with them. So far i use the below script on the cubes but as soon as i press Play they dissapear. What’s the trick here? What kind of if statement do i need? Also when i want to use OnCollisionEnter to destroy something i attach the script to the destroyer or the destroyed? Thanks!
function OnCollisionEnter(){
GameObject.Destroy(gameObject);
}
Currently you have your cubes set to destroy themselves as soon as anything collides with them. In your case I would assume they are colliding with the floor as soon as you start the game and being destroyed. If you are keeping this script on your cubes you will want to do something like:
function OnCollisionEnter(collision:Collision){
if(collision.gameObject.tag == "Player"){
Destroy(this.gameObject);
}
}
Be sure that your Player is tagged as “Player” for this example.