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 /
avatar image
0
Question by Der_Kevin · Apr 28, 2016 at 01:29 PM · animationuievent

Chain UI animations with Events?

Hey! so i want to do this ui animation where every slot pops up with a small delay. something like this: https://media.giphy.com/media/xT1XGB4HHqRP8aNtlu/giphy.gif (Iam talking about the the appearance of the building slots (Landing Craft, Radar, Armory...))

what i did so far is, creating the pop up animation called "slot_open" with a event that calls the function StartNextTabAnimation() from the ActivateNextAnimation.cs at frame 60of100,and having this script to gather all the slots inside a canvas:

 using UnityEngine;
 using System.Collections;
 using System.Linq;
 
 public class AnimateSlots : MonoBehaviour {
 
     public GameObject[] m_Slots;
 
     private void Update ()
     {
 
         GameObject[] m_TargetsGO = GameObject.FindGameObjectsWithTag("Slots").OrderBy( go => go.name ).ToArray();
 
         m_Slots = new GameObject[m_TargetsGO.Length];
 
         for(int i = 0; i < m_TargetsGO.Length; ++i)
         {
             m_Slots[i] = m_TargetsGO[i];
         }
 
 
 
     }
 }

so my hierarchy is this:

 -Canvas
 --BuidMenu (where the AnimateSlots.cs is on)
 ---Slot1 (Button with Animator&ActivateNextAnimation.cs)
 ---Slot2 (Button with Animator&ActivateNextAnimation.cs)
 ---Slot3 (Button with Animator&ActivateNextAnimation.cs)
 ---Slot4 (Button with Animator&ActivateNextAnimation.cs)

so with the script above, i get a list with all slots inside the BuildMenu (cause you dont know how many slots will be in there). and on the Slots1-4 there is a Animator and this Script:

 using UnityEngine;
 using System.Collections;
 
 public class ActivateNextAnimation : MonoBehaviour
 {
     public Animator nextTab;
 
     public void StartNextTabAnimation()
     {
         if (nextTab != null) nextTab.Play("slot_open");
     }
 }
 

so my problem now is, that i have to place all the nextTabs by hand in the Slots1-4 So at slot1 i have to drag in the animator of slot2 and so on which isnt pretty much dynamic.

by the way: the very fist animation for Slot1 gets triggered by a Button which is not inside the BuildMenu using the Button component OnClickEvent (Animator.Play).

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
0
Best Answer

Answer by Link0n3 · Apr 28, 2016 at 02:48 PM

I am assuming the order in which you take the slots is also the order in which you want to make them appear. Following what you are trying to do I could suggest to add something like this in the AnimateSlots class and calling when creating the list.

 private void SetAnimationLinks()
 {
     for(int i =  0; i < m_Slots.Length - 1; i++)
     {
          //Linking 0 -> 1; 1->2 and so on...
          m_Slots[i].GetComponent<ActivateNextTabAnimation>().nextTab = m_Slots[i + 1].GetComponent<Animator>();
     }
 }

Other suggestions: pay attention of using Update since it is called by the engine at every frame even when using private (I guess they use Reflection to do that). Therefore you should move the list creation in a different method called when needed. There is no need to create an additional array to populate the public one. You can directly populate that.

A completely different implementation (but more clear from my point of view) could be writing a coroutine to activate the animator. So when the Button is pressed (activating the first animation) you can do something like

 public void OnButtonClickedEvent()
 {
    StartCoroutine(ActivateAnimation(0.2f);//200 ms
 }
 
 IEnumerator ActivateAnimation(float delay)
 {
     for(int i = 0; i < m_Slots.Length; i++)
     {
           m_Slots.GetComponent<Animator>.Play("slot_open");
           //You can adjust the dealy whn calling the coroutine
           yield return new WaitForSeconds(delay);
     }
 }

I hope this can give some help.

Cheers.

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 Der_Kevin · May 02, 2016 at 10:11 AM 0
Share

thanks! good idea with the coroutine delay. but somehow this line: m_Slots.GetComponent.Play("slot_open");

seams to be wrong?

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

91 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

Related Questions

is there a simple way to display a UI box around multiple animated meshs? 0 Answers

Creating a function to use as an event in an animation? 1 Answer

Animating a Panel,Animating a panel 1 Answer

Make Animation Loop X Times C# 2 Answers

how to make ui button run an animation 0 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