- Home /
Door with Key script ... animation will not play
I have watched videos, read comments and tutorials and still can not just my door animation to would with script ... Noob to coding ....
here is the door open script i have made for the door ... Please Help Me
static var gotKey : boolean = false; // the var which u want to call for key script
var smooth = 2.0;
var openDoor : String;
var closeDoor : String;
var open : boolean = false;
var enter : boolean = false;
var openDoorSound : AudioClip;
var closeDoorSound : AudioClip;
function Update (){
if(open == true){
animation.Play(openDoor); //The part of opening the door
if(animation.IsPlaying(openDoor));
audio.Play (); //audio sound for opening the door
}
if(open == false){
animation.Play(closeDoor); //The part for closing the door
if(animation.IsPlaying(closeDoor));
audio.Play(); //audio sound for closing the door
}
//the part for pressing smt to open
if(gotKey && enter){
if(Input.GetKeyDown("e")){
open = true;
GUIkey.guiEnable = true;
alert = "Authorized Hand Scan Required";
}
}
}
//in here you just call if Player enter the trigger is true
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
enter = true;
}
}
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") {
enter = false;
}
}
I pick up the key and enter the trigger ... that part works ... the gui comes up on screen and press "e" and then nothing .... Thanks for any knowledge and assistance
Sorry if I can't help with you script, but the first thing you could do is put a Debug.Log("TEST"); line in your parts of your script so you see exactly where the script doesn't work as intended.
$$anonymous$$aybe your door is static , make sure is not.
I found some posts online about same problem and added this to my script and animation now plays ...
for (var state:AnimationState in animation) {
if(state.clip == doorOpen) {
openState = state.name;
}
else if (state.clip == doorClose) {
closeState = state.name;
}
so it plays when entering trigger ... but still not with key ... So I added another empty game object that interacts with key ... but not sure how to destroy it after its served its purpose
thanks for replys peoples ...
Your answer
Follow this Question
Related Questions
Automatically duplicate animation from imported file 2 Answers
How to Serialize an AnimationState 0 Answers
Animating an Animation Parameter with Mecanim 0 Answers
Legacy animation loop pose? (for walk/run clips) 0 Answers
Keyframe at exact values? 0 Answers