- Home /
Question by
HammockHead · Dec 18, 2012 at 02:33 AM ·
animationdoorautomatic
Trouble with Animation
I have a problem with this door opening script. On collision with the trigger collider, the door collider is supposed to disable and an animation is supposed to play and similarly when on exit of the trigger collider, the door collider is supposed to enable and an animation is supposed to play. However, in reality only the door collider is disabled.
var timeOpen : float ;
var doorOpenSound : AudioClip ;
var doorCloseSound : AudioClip ;
private var doorIsOpen : boolean ;
private var doorTimer : float = 0.0 ;
private var isBlocked : boolean = false ;
function Update () {
if(doorIsOpen && isBlocked == false) {
doorTimer += Time.deltaTime ;
if (doorTimer > timeOpen && isBlocked == false) {
ShutDoor () ;
doorTimer = 0.0 ;
if (doorTimer > timeOpen && isBlocked == true) {
doorTimer = 0.0 ;
}
}
}
}
function OnTriggerEnter(other : Collider){
if(other.gameObject.tag == "Player" && doorIsOpen == false){
isBlocked = true ;
OpenDoor () ;
}
}
function OnTriggerStay (other : Collider){
if (doorIsOpen == false){
isBlocked = true ;
OpenDoor () ;
if (doorIsOpen == true) {
isBlocked = true ;
}
}
}
function OnTriggerExit (other : Collider){
if(isBlocked == true) {
isBlocked = false ;
doorTimer = 0.0 ;
}
}
function OpenDoor () {
audio.PlayOneShot (doorOpenSound) ;
doorIsOpen = true ;
animation.PlayQueued ("dooropen") ;
}
function ShutDoor () {
audio.PlayOneShot (doorCloseSound) ;
doorIsOpen = false ;
animation.PlayQueued ("doorclose") ;
animation.PlayQueued ("dooridle") ;
}
@script RequireComponent (AudioSource)
@script RequireComponent (BoxCollider)
Comment
Your answer
Follow this Question
Related Questions
multiplying door problem!! 2 Answers
Object gone aftar play - Animation problem. 0 Answers
Child problem in animation 1 Answer
Humanoid Alters The Animation 1 Answer
Animation clip does not exist? 1 Answer