Hi guys, I’m unsure what is going on.
I admit it, I just copied it from somewhere from the internet (after all, what’s the point in typing it all out?). Don’t get me wrong, I understand what is being done, it is just that the animation isn’t working, as this is the first time I’ve done something like this.
private var doorIsOpen : boolean = false;
private var currentDoor : GameObject;
var doorOpenSound : AudioClip;
var doorCloseSound : AudioClip;
function Update () {
if (Input.GetButtonDown("Fire1") ) {
var hit : RaycastHit;
if(Physics.Raycast (transform.position, transform.forward, hit, 2)){
Debug.Log(hit.collider.gameObject.name);
if(hit.collider.gameObject.tag == "door" doorIsOpen == false){
currentDoor = hit.collider.gameObject;
Door(doorOpenSound, true, "dooropen", currentDoor);
}else if(doorIsOpen == true){
currentDoor = hit.collider.gameObject;
Door(doorOpenSound, false, "doorclose", currentDoor);
}
}
}
}
function Door(aClip : AudioClip, openCheck : boolean, animName : String, thisDoor : GameObject){
audio.PlayOneShot(aClip);
doorIsOpen = openCheck;
thisDoor.animation.Play(animName);
}
@script RequireComponent(AudioSource)
I think it has to do with “dooropen” and “doorclose”. The animation is set in door_animation, with the frame staying static and the door panel moving. The animation has been split so the correct frames have the correct name, but is just not animating.
I’ve also tried thisDoor.transform.parent.animation.Play(animName);
and it still not work.
My Animation is set up as
door_animation
Animation: idle
Animations
Size 3
Element 0 idle
Element 1 dooropen
Element 2 doorclose
Animate Physics
frame mesh collider
door box collider
Any ideas?