Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Daimien · Feb 20, 2015 at 05:26 PM · animationuiscript.

how to make ui button run an animation

I'm trying to make a button on my main menu run an animation to move that menu off screen and move a new menu on the screen (like on my main menu if i hit my settings button it moves my main menu of screen and my settings menu on screen) i have all the animations all ready i just need a script to run it I'm not so good with script and could use some help. 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

1 Reply

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

Answer by Mmmpies · Feb 20, 2015 at 07:27 PM

OK this is a basic script that'll give you an idea of what to do. The two panels go into the public slots and you need a bool on each panels Animator called SwitchMenu. On one of the Menus play the exit Animation if true and on the other the enter Animation if true. Then do the opposite for the false settings for the bool. Make sure you switch off Loop for the animations.

Drag this script onto the canvas:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class MenuSwitch : MonoBehaviour {
 
     private Animator p1Anim;
     private Animator p2Anim;
     private bool swapPanel = false;
 
     public RectTransform panel1;
     public RectTransform panel2;
 
     // Use this for initialization
     void Start () {
         p1Anim = panel1.GetComponent<Animator>();
         p2Anim = panel2.GetComponent<Animator>();
     }
     
     public void IveBeenClicked()
     {
         swapPanel = !swapPanel;
 
         p1Anim.SetBool("SwitchMenu", swapPanel);
         p2Anim.SetBool("SwitchMenu", swapPanel);
     }
 }

On the button on each panel that swaps click + on the OnClick and drag the canvas onto the the slot that appears. From the dropdown select MenuSwitch -> IveBeenClicked.

Should be able to swap between two panels, I could in a quick test.

Example script in C#

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 Daimien · Feb 22, 2015 at 04:10 PM 0
Share

thanks a lot i got every thing set up except I'm not sure where to put this in (like how to do this part)

On one of the $$anonymous$$enus play the exit Animation if true and on the other the enter Animation if true. Then do the opposite for the false settings for the bool.

avatar image Mmmpies · Feb 22, 2015 at 04:34 PM 0
Share

O$$anonymous$$ you have to open the Animator Window for each menu and give it 2 states (actually you probably want more but lets just get this fixed first)

$$anonymous$$ecanimAnimator

Have the animation to exit and the animation to enter. Right click on one and select $$anonymous$$ake Transition and click on the other button to make a transition. Do the same for the other button.

Click on the bottom left + to add a parameter and select bool. Name the bool Switch$$anonymous$$enu.

Click on the arrow and set the Condition to be Switch$$anonymous$$enu True or False and do the opposite for the other arrow.

Now open the other menu panel's Animator and copy what you just did but switch which arrow uses true and which uses false.

mecanimenterexit.png (5.8 kB)

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

Animation script help light problem 0 Answers

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

the animation walk but he still in the same place and rotate left and right on this white circle 0 Answers

First script plays animation but second script stops if from playing said animation 1 Answer

Animating a Panel,Animating a panel 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