• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MetalsGames · Mar 22, 2015 at 11:03 AM · animationjavascriptscripting problemanimatortrigger

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

alt text

alt text

3.jpg (91.7 kB)
1.jpg (77.3 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gibberingmouther · Jul 14, 2017 at 01:56 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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");

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Animation Trigger is saved even if it is not used immediately. 1 Answer

Animator SetTrigger inexplicably not firing 1 Answer

Why the speed parameter in Animator change the animation speed only for door open but when the door is closing the speed still very fast ? 1 Answer

hash does not exist error 1 Answer

How to properly detect the end time of an Animation which wait for the end of the previous one ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges