Like the title says, I have a open/close door animation and I want an another animation to play when I open the door and only when I open the door. Here the script I used to trigger the door animation:
#pragma strict
private var guiShow : boolean = false;
var isOpen : boolean = false;
var door : GameObject;
var rayLength = 10;
var customSkin : GUISkin;
var DoorOpenSound : AudioClip;
var DoorCloseSound : AudioClip;
function Update()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
if(hit.collider.gameObject.tag == "Door")
{
guiShow = true;
if(Input.GetKeyDown("e") && isOpen == false)
{
door.animation.Play("OpenDoor");
isOpen = true;
guiShow = false;
audio.PlayOneShot(DoorOpenSound);
}
else if(Input.GetKeyDown("e") && isOpen == true)
{
door.animation.Play("CloseDoor");
isOpen = false;
guiShow = false;
audio.PlayOneShot(DoorCloseSound);
}
}
}
else
{
guiShow = false;
}
}
function OnGUI()
{
if(guiShow == true && isOpen == false)
{
GUI.skin = customSkin;
GUI.Box(Rect(Screen.width / 2, Screen.height / 2, 100, 25), "E open");
}
if(guiShow == true && isOpen == true)
{
GUI.skin = customSkin;
GUI.Box(Rect(Screen.width / 2, Screen.height / 2, 100, 25), "E close");
}
}