how do u make a script when u collide with a rotating object, it disappears and subtracts 1 from a variable?
I don't know why people keep posting answers here where they use triggers wrong. Triggers are intended to for instance make an invisible forcefield that when you walk through it the door in front of you slides open. You 'can' use them for collision, but it's easier to just use:
var score : int = 10;
function OnCollisionEnter (col : Collision) {
if(col.gameObject.Tag == "Player"){
score -=1;
Destroy(gameObject);
}
}
Now all you have to do is attach this to the rotating object and make sure your playercharacter has the tag Player. :)
This is what I would use...
var score : int = 10;
var objectTag : String = "Put The GameObjects Tag Here";
function OnCollissionEnter (collidedObject : Collision) {
if(collidedObject.gameObject.tag == objectTag){
score -=1;
Destroy(gameObject);
}
}
-Hope I Helped!
Thanks Joshua for the original code...
It would be something like this:
var MyVar = 10;
function OnTriggerEnter (other : Collider) {
if (other.CompareTag ("HERE YOUR TAG NAME")) { Destroy (gameObject); MyVar--; } }
I hope it helps, good Luck.