- Home /
Question by
monocular · May 06, 2011 at 06:48 AM ·
collisionbeginneroncollisionenter
Register collision between two specific game objects, using var (not tags or names).
Hello, this is probably redundancy overload but I'm such a noob that'll ask you to bear with me....
What I have is this:
private var beenHit:boolean = false; private var timer:float = 0.0;
static var targetHit = 0;
var targetRoot:GameObject;
var NPC:GameObject;
var hitSound:AudioClip;
var resetSound:AudioClip;
function OnCollisionEnter(theObject:Collision) {
print("Animate Object Hit1");
if(beenHit == false && theObject.GameObject.name == "Kenny") {
targetRoot.animation.Play("animate");
beenHit = true;
}
}
function Update () {
if(beenHit) {
timer += Time.deltaTime;
}
if(timer > 3) {
print("Target Timer");
targetRoot.animation.Play("idle");
beenHit = false;
timer = 0.0;
}
}
And what I would like is to, rather than detecting "Kenny" it will detect the var NPC. This may be super simple but I'm not seeing it so... help?
Thanks!
Comment
Best Answer
Answer by DaveA · May 06, 2011 at 06:50 AM
theObject.GameObject.name == NPC.name
Yup, super simple... I think I'll go bash my head in now.
Thank you!