Hello unity3d world. I need help… I have a main character, a sphere… I can move by pressing the arrow keys. I have also some cubes on my map. The sphere with which I move has tag “Player” and the cubes have tag cube… Now I want I I hit the cubes with my sphere, that the cubes die. Something like destroying the gameobject. I need a simple script please;)
You need to use triggers. Select all the cubes, in the inspector window select trigger for the Collider. then make a javascript like this :
function OnTriggerEnter( other : Collider){
if( other.gameObject.tag == “cube”){
Destroy(other.gameObject );
}
}
add this Script to the sphere that the user controls. sorry i am on my cell phone now so i can’t format the code … I Hope this helped!
function OnTriggerEnter(Collider col){
if( col.tag == “Player” ) Destroy( gameObject );
}
That script on the cube. Now the signal won’t be sent if you’re moving the sphere by translation. You need either a charactercontroller, use rigidbody.AddForce or have a kinematic object. In that last case, the cube will need a non-kinematic rigidbody to be “awakened”.