Hey I wrote a script that will run an open door animation if certain criteria’s as met with.
var Anim : AnimationClip;
var AnimC : AnimationClip;
var open = false;
function OnTriggerEnter () {
if(!open && Input.GetButton("Fire1")){
animation.Play("Anim");
open = true;
}
if(open && Input.GetButton("Fire1")){
animation.Play("AnimC");
open = false;
}
}
Anim is the open animation
aimC is the close animation
But the animation won’t play. I have a trigger on the door with a animator plus animation. I have also set it to play automatically and it does but just not with player input.
I debug.log the code and the trigger does trigger, it’s just it doesn’t get past the first if statement.
Any help would be appreciated.
Maybe the “other : Collider” is missing ?
function OnTriggerEnter (other : Collider)
My best thoughts on this is that whatever “Fire1” is assigned to is not being triggered, and thus those if statements are moot. If it does fire though, then you’re going to have it rapidly playing both of those when the player does press the Fire1 button.
Try using:
Input.GetKeyDown("Fire1")
If that doesn’t work, try re-assigning the key to something else and see if that works.
Fixed it!
var open = false;
var intrigger : boolean = false;
function OnTriggerEnter(){
intrigger = true;
}
function Update(){
if(intrigger){
if(!open && Input.GetButtonDown("Fire1")){
clip1();
}
}
if(intrigger){
if(open && Input.GetButtonDown("Fire1")){
clip2();
}
}
}
function clip1(){
animation.Play(anim);
yield WaitForSeconds (animation[anim].length);
open = true;
}
function clip2(){
animation.Play(animc);
yield WaitForSeconds (animation[animc].length);
open = false;
}