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 Hollow Jack · Feb 25, 2015 at 08:58 PM · animationuibutton

Launching an animation with new GUI in Unity 4.6

Hello,

I was wondering about launching a simple animation triggered by a button.

For example : my scene has a simple cube with two animations ( Take 001 is a translation animation, and take 002 is a rotation animation. ), one canvas, three buttons attached ( One button "Translate", one button "Rotate" and one button "Quit". ), one empty GameObject on which I linked my scripts.

In my Animator Controller, named Cube_AC, I have the two states Take 001 and Take 002 linked on Any State and I created two triggers named respectively GoTake001 and GoTake002 for the transitions.

I tried different ways to launch any of the two animations by script but I never succeed ( I tried to link some script in the OnClick section of the button but the animation won't play. ) All that my scene is doing is playing the two animations one after another ( my default state is Take 001 ). But when I click on the button nothing happens.

Have some kind of ideas on how I could do?

This is just a test scene, I want to build some kind of 3D player in Unity.

I'm scripting in C# and i'm a real beginner.

Thanks a lot for the help!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by spiceboy9994 · Feb 27, 2015 at 06:33 PM

Maybe you need to set up your animator to have two different states, attach Take001 to one state and Take002 to the other one, add transitions between them and set conditions for your animation transitions from one state to another within your animator.

"Any state" I think cannot be end for any transition based animations. Here's the explanation for any state state:

http://docs.unity3d.com/Manual/class-State.html

By default the animator always create the transitions conditioned by "Exit Time" that's the reason that the states could be executing one after another.

Here's a bit more detail about how to do that:

1-Create a Paramater for your animator:

http://cdn2.raywenderlich.com/wp-content/uploads/2015/02/parameter_menu.png

2-Create a transition between your 2 states

3-Change the transition to be controlled by your parameter

http://cdn2.raywenderlich.com/wp-content/uploads/2015/02/condition_param_menu.png

4-Whenever you want the animator to switch states, add a trigger within your game logic (could be a collision, a button click, a key input detection) and change the value to this parameter

 var anim = gameObject.GetComponent<Animator>();
 // Sets the value
 anim.SetBool("ParamName", true); 
 // Gets the value
 bool isInConga = anim.GetBool("ParamName");

Here's the complete tutorial in case you need it:

http://www.raywenderlich.com/66523/unity-2d-tutorial-animation-controllers

Regards

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Prevent animation from starting the first time 0 Answers

Animation works only once on button click 4 Answers

Can I make animations snap to a frame? 1 Answer

Animating UI (4.6) parameters is creating garbage keyframes on child objects 0 Answers

Activating One Part of An 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