Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Danao · Sep 15, 2014 at 06:34 AM · animationanimatortriggerbool

How can I setup my bool/trigger in animator?

Hi, I'm new to Unity (and C#) and trying to link my bool and my animation in animator to play correctly.

I have my bool:

bool shoot = Input.GetButtonDown("Fire2");

And I have my animation set up on the player and it is playing (just looping infinitely despite the looping box being unchecked for the animation.

How can I get my bool to activate the parameter "shoot" in animator? I've tried to set a bool and a trigger, but can't seem to get either to play the animation once on button press ("Fire2") and then set to false. Any help would be greatly appreciated!

Comment
Add comment · Show 2
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 tanoshimi · Sep 15, 2014 at 06:36 AM 1
Share

Trigger is what you want for a "one-shot" state change trigger. What exit conditions do you have in the shooting animation state in the animator? Assu$$anonymous$$g these are met, it should transition straight away once the animation has played.

avatar image Danao · Sep 15, 2014 at 03:43 PM 0
Share

Hi tanoshimi and thanks for the comment! It looks like I had a bunch of views before you chimed in, but no advice :) It turns out the trigger is what I wanted and I have the exit conditions set as the name of my trigger in the animator parameters. It's mostly working now and I think if I just adjust my animations a bit, it'll be fine. What I ended up doing was calling for the animator using GetComponent (again) right after my bool, then I could use SetTrigger without any problems for the animation!

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Danao · Sep 16, 2014 at 03:37 AM

Here is the snippet of code that worked for me in case someone comes across this with the same problem:

     bool shoot = Input.GetButtonDown ("Fire2");  //Attack button and animation
                     
     if (shoot) {
         Animator animator = GetComponent<Animator>() as Animator;
         animator.SetTrigger("Attack");


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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How to start animation after object is destroyed ? 0 Answers

Firing triggers and playing animations in sequence 0 Answers

How do I setup a Shooting Trigger to make an Animation play on a Platform? 0 Answers

i need the animation to be trigger on a specific time but it is not trigger, script got no error. Not sure where is the problem, need help please. 1 Answer

Triggering a Player Hit Animation 2 Answers


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