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 neeeb · Oct 10, 2014 at 11:05 AM · c#animationanimatormecanimlegacy

How to use mecanim to play specific animation clips when public static int condition is reached?

Im currently using a public static int condition to play various animations, for e.g.

 using UnityEngine;
 using System.Collections;
 
 public class CubeRiseControl : MonoBehaviour
 {   
 
 public AnimationClip CubeRise;
 
     void Update ()
     {
         if (SetButInc.nextNum == 2)
         {
             animation.Play("CubeRise");
         }
     }
 }

To call animation clips in this way they need to be in legacy, type 1. However, the downside of switching to legacy animation clips is that they limit how I can animate the RGBA values, more specifically how to fade some objects but not others. If I go back to using type 2 animation clips, can I use mecanim/animator to do the same job, i.e. play an animation clip only when a public static int condition is met?

Not looking for a full solition, just a nudeg in the right direction. Thanks.

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

2 Replies

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

Answer by Baste · Oct 10, 2014 at 03:35 PM

This is exactly what mechanim is made for.

You set up your mechanim with a transition to the clip CubeRise on a trigger, and set that trigger when you need to switch the animation.

With that setup, your code would be:

 public Animator CubeAnimator;
  
 void Update ()
 {
     if (SetButInc.nextNum == 2)
     {
         CubeAnimator.SetTrigger("CubeRise");
     }
 }

Now, there's something strange going on - you're starting the animation clip on every frame. Are you supposed to be doing that? If you're going to be using mechanim, you want to send the trigger message only once for every time you switch to that clip, so you'd have to rewrite your system to take that into account.

Comment
Add comment · Show 2 · 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
avatar image neeeb · Oct 13, 2014 at 07:52 AM 0
Share

That's just what I wanted to hear. RE: Update(), for reasons unknown to me this is the only way I could get my Type 1 animations play, they were set to Clamp Forever so they would only play once then stop on the last frame. I agree this isn't very logical and I questioned it when it was suggested to me.

I have my animation clips set to Type 2 and have added your script however I'm not sure how to set the trigger as you suggest. I see the trigger parameter window in mecanim but can't understand how to set it. At present my 3 animation clips play in loop as as soon as I start the game.

avatar image neeeb · Oct 13, 2014 at 09:11 AM 0
Share

Ok, I think I understand the trigger parameter now. Lets say I have an Idle animation where nothing happens and CubeRise where the cube rises by 20 in Y. I want the game to start with the cube Idle and only animate CubeRise when nextNum = 2, as in above script.

In my animator controller I have added the two clips with a transition going from Idle to CubeRise with a condition = CubeRise (trigger parameter). Im now expecting that when I start the Idle animation plays in loop until nextNum = 2, where the trigger CubeRise condition is met and CubeRise animation plays. However the result I have is that CubeRise animation plays as soon as the game starts. I think im still missing something somewhere along the line?

avatar image
0

Answer by neeeb · Oct 13, 2014 at 10:21 AM

alt text

Ok, I now start on IdleCubeStart with the CubeRise Trigger condistion to CubeRise animation. Then exit time = 1 transition to IdleCubeRisen (cube idle in risen position). Still the same problem CubeRise animation playing from the start, when it should be triggered by script when nextNum=2. All other objects like text react perfectly to nextNum values so I know that is not the issue.


capture.jpg (53.5 kB)
Comment
Add comment · Show 1 · 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
avatar image neeeb · Oct 13, 2014 at 11:41 AM 0
Share

So it turns out I was being a fool and left the trigger checked ON when it should have been OFF. Thanks for your help!

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

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animator not showing animation 1 Answer

Mecanim combo system occasionally stops and registers phantom clicks 0 Answers

Issue with mecanim playing an animation using setbool 1 Answer

[Unity 4.3] Skinned legacy animations do not work 1 Answer

Animation (Legacy) vs Animator (New). 5 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