- Home /
Animator Trigger Not Working
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
i'm having a similar error. stringtohash used to work but now it's giving me an error. i don't think it's the same problem you're having, but it's similar ... i had it working in 5.5, and tried it with a different set of animations in 5.5 - now it doesn't work. just thought i'd mention it, both being stringtohash related problems.
Answer by TeohRIK · Jul 14, 2017 at 03:17 AM
So weird, my 1 is working fine, but I using Animator.StringToHash
Maybe u try with this
LargeBoxOpenHash = Animator.StringToHash("OpenLargeBox");
LargeBoxCloseHash = Animator.StringToHash("CloseLargeBox");
Edit:
Oh ya...I juz checked my code, I do the string to hash outside the start function
var LargeBoxOpenHash : int = Animator.StringToHash("OpenLargeBox");
var LargeBoxCloseHash : int = Animator.StringToHash("CloseLargeBox");