- Home /
Just needed to check "has exit time" in transitions where the boolean is changed.
UI buttons->panels animation management
Hello guys! I've been working on a demo of my project for a while, and got some troubles with main menu.
For example, I have buttons like "button1", "button2", "button3" etc (all of them have super cool looking sprites and animations and sounds and damn they're cool but that's not the point). These buttons make "panel1", "panel2" and "panel3" appear, wich is an animation of them moving from the right to the close center of the screen.
I want these buttons to open their own panel while closing another ones. If I hit "button2" when "panel1" is open, "panel1" should go back to the right of the screen outside the camera, and "panel2" should go to the center of the screen, and all panels play their animations simultaneously. Also if I press same button two times in a row, it should open and close the panel it controls.
I'm kinda beginner in Unity, so I made it this way:
created 3 states for each pannel. "Off" - entry state when the scene starts (has loop), "Open" - moving to the center, and "Close" - moving outside the camera where it has been before.
Also added two transitions between "Open" and "Close", and they set the animation bool "Isopen" to true and false
created script for each button with public references to the panels, gameobjects and animators. I named them "Play button", "Exit button" etc, but I apply them to the panels, who have animators needed to trigger. Here is is... I believe it will make you laugh, but hey I tried my best with my current low skills:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ExitButton : MonoBehaviour {
// 1. Reference to the play panel; public PlayButton playbut; public Animator playbuta; public bool open; Animator thisanim; void Awake () { open = false; thisanim = GetComponent<Animator>(); } public void ButPanAnimTrigger() { open = !open; thisanim.SetBool("Isopen", open); //Checking if other panels are open //1. Exit panel check if ((playbut.open) == true) { playbut.open = false; playbuta.SetBool("Isopen", false); } } }
Here's a picture of animator's structure:
While this, to my surprise, works, the problem is that sometimes (more often than expected) there is a delay when you press buttons fast enough, it can vary up to 0,8 or 1 second, wich can be annoying and I want to get rid of it. Any advice?
Answer by Vardas96 · Jan 29, 2017 at 02:21 AM
Allright, I fixed the issue, and the answer is quite simple. I just needed to uncheck "has exit time" in transitions that change the boolean, and now my panels are responding to buttons really fast.
Follow this Question
Related Questions
UI Animation Not Playing 1 Answer
Animating a Panel,Animating a panel 1 Answer
Animation not playing on game object activated by script 3 Answers