Search Unity

A small but annoying delay in my UI system

Discussion in 'Editor & General Support' started by Cyrill9, Jan 23, 2017.

  1. Cyrill9

    Cyrill9

    Joined:
    Oct 7, 2016
    Posts:
    8
    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 transitions between "Open", "Close" and "Off", and they set the animation bool "Isopen" to true and false (see screenshot below).

    • 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 it is... I may make you laugh, but hey, I tried my best with my current low skills:

      Code (CSharp):
      1.     using System.Collections;
      2.     using System.Collections.Generic;
      3.     using UnityEngine;
      4.    
      5.     public class ExitButton : MonoBehaviour {
      6.    
      7.         // 1. Reference to the play panel;
      8.         public PlayButton playbut;
      9.         public Animator playbuta;
      10.    
      11.         public bool open;
      12.         Animator thisanim;
      13.      
      14.         void Awake ()
      15.         {
      16.             open = false;
      17.             thisanim = GetComponent<Animator>();              
      18.         }
      19.         public void ButPanAnimTrigger()
      20.         {
      21.             open = !open;
      22.             thisanim.SetBool("Isopen", open);
      23.            
      24.             //Checking if other panels are open
      25.    
      26.             //1. Exit panel check
      27.             if ((playbut.open) == true)
      28.             {
      29.                 playbut.open = false;
      30.                 playbuta.SetBool("Isopen", false);
      31.             }
      32.         }
      33.     }
    Here's a picture of animator's structure:
    123.jpg

    While this, to my surprise, works, the problem is that sometimes (more often than expected) there is a delay before the panel you need appears 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?
     
  2. Cyrill9

    Cyrill9

    Joined:
    Oct 7, 2016
    Posts:
    8
    Actually, I believe all I have to do is just adjust the transitions to switch animations faster.

    EDIT: Yes, I just had to uncheck "has exit time" in transitions where the boolean is changing.
     
    Last edited: Jan 28, 2017