Hello,
Im trying to use the Animator to trigger two different animations “OpenLargeBox” and “CloseLargeBox”. You walk up to the Large Box that has a trigger parented to it with a script that checks OnEnterStay if you are tagged Player and if the player has pressed “E” to activate the “OpenLargeBox” Animation in the Animator.
so what should happen is if the Large Box is closed you should be able to walk into the trigger press “E” and it activates the “OpenLargeBox” animation. if the Large Box is Opened you should be abled to walk into the trigger and press “E” and it activates the “CloseLargeBox” animation.
Here is the link to the video tutorial i watched and based it off of. (http://unity3d.com/learn/tutorials/modules/beginner/animation/animator-scripting)
Iv done this before but with the unity 5 update its now not working for me, any help is much appreciated, Thanks in advanced.
Here is the code that is on the Large Box Trigger
#pragma strict
var LargeBox : GameObject;
var LargeBoxAnim : Animator;
var LargeBoxOpenHash : int;
var LargeBoxCloseHash : int;
var LBOpen : boolean;
function Start ()
{
LargeBoxAnim = LargeBox.GetComponent (Animator);
LargeBoxOpenHash = LargeBoxAnim.StringToHash("OpenLargeBox");
LargeBoxCloseHash = LargeBoxAnim.StringToHash("CloseLargeBox");
}
function OnTriggerStay (other : Collider)
{
if(other.tag == "Player")
{
if(Input.GetButtonDown("OpenBox"))
{
if(LBOpen == false)
{
LargeBoxAnim.SetTrigger (LargeBoxOpenHash);
}
if(LBOpen == true)
{
LargeBoxAnim.SetTrigger (LargeBoxCloseHash);
}
LBOpen = !LBOpen;
}
}
}
Screen Shots