Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by F_J · Apr 29, 2016 at 04:35 PM · c#animationfpsanimator controllerkeyframes

Why is scripting animation not so responsive in unity?

Hi,

What am I doing:

Making a menu system!

What I Want:

I want to play an animation on my menu elements whenever the menu is in an open or closed state. However, my menu also has an open and close animation in their respective states. So when I transition from one menu to another I want the current menu elements animation to close first then its menu and when the next menu opens I want the menu to play open animation first then its elements. But this all depends on the kind of transition I am setting, therefore, I am coding it in a generic form, so it's fully configurable by the editor.

The Approach I Took:

  1. I am using Unity's Mecanim system to achieve his.

  2. I have attached animator to all the elements and menus that need animations on them.

  3. I have made two scripts "UIManager.cs" and "ElementAnimator.cs".

  4. I have attachment the "UIManager.cs" at the Canvas Level and "ElementAnimator.cs" at the Menu Level.

  5. I have created multiple parameters for my menu animator for the various transitions.

  6. In UI manager, I have created menu linkages and I also set the animator parameter when the transition OnClick event is called.

Problem with ElementAnimator.cs script:

This is the code I have written for ElementAnimator.cs:

 public bool playMenuElements;
 public bool value;
 public Elements[] elements;
 
 void SetBool(bool value) {
     for (int i = 0; i < elements.Length; i++) {
         if (elements [i].animator != null && elements [i].parameter != "")
             elements [i].animator.SetBool (elements [i].parameter, value);
     }
 }
 
 void Update() {
     if (playMenuElements) {
         Debug.Log (this.gameObject.name + " " + playMenuElements);
         SetBool(value);
     }
 }

In the inspector, I key the playMenuElements variable to true or false at the desired frame. I set it back to false in the next frame in order to avoid any unnecessary memory usage. However, the problem is that the function SetBool() is called sometimes. Whys isn't unity working properly? Am I doing something wrong? Is my approach bad? Can anyone help me out in this? Can't think of anything, running out of options and ideas :(

What I Think

The call is dependent on the fps rate which explains the randomness in the SetBool call through the key. I have tried skipping few frames and then setting the variable to false. It gets called three or fours times, but it's still not consistent! I just need to call it once through the keyed variable.

Thanks in advance.

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

0 Replies

· Add your reply
  • Sort: 

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

175 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 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 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 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 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 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 avatar image

Related Questions

I can't make transition from actual animation to previous one 1 Answer

Unity C# Script error: CS1501 1 Answer

Animating in c# 1 Answer

Animations get screwed up when I add OnAnimatorMove function 0 Answers

MobController 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