Hey all
I am very new to Unity, so please go easy on me.
What i’m trying to create is simple animation using the UI, so when a UI button is clicked, an Object animation starts, and when you click the UI button again, it reverses back to original positon.
The project works fine, and when the UI button is clicked an animation starts, but my problem is that there’s a strange delay before the animation starts when the button is clicked, which seems to have a varied delay, and I can’t seem to see what’s causing this delay.
This is the only way I could figure out how to do it, and this is what im doing to create the effect (I dont think i’ve missed anything out)
++++++++++++++++++++++++++
1: Added Cube
2: Clicked cube and select animation from (Window > Animation)
3: Create random animation and turned off Loop and Autostart
4: Applied a parameter “Ani_Speed” to the animation
5: Created C# script
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Ani_Tester : MonoBehaviour
{
public Button Button;
public Animator Animation;
public Canvas Canvas;
public string Status;
void Start ()
{
Button = Button.GetComponent<Button> ();
Animation.enabled = false;
Canvas.enabled = true;
}
public void Press()
{
Button.enabled = true;
Status = Button.tag;
if (Status == "Inactive")
{
Button.tag = "Active";
Animation.SetFloat ("Ani_Speed", 5f);
}
else
{
Button.tag = "Inactive";
Animation.SetFloat ("Ani_Speed", -5f);
}
Animation.enabled = true;
}
}
6: Created 2 tags (Active \ Inactive)
7: Added a UI button and assigned the tag “Inactive”
8: Dragged animation script to Main Camera
9: In Inspector for Main Camera, dragged;
The UI Button to “Button”
The Object to “Animation”
The UI Canvas to “Canvas”
10: Clicked the UI button and under Inspector
Under “On Click()”
Click + Symbol
Dragged main camera to “Runtime C” drop down
Drop down selected “Ani_Tester”
Selected Press();
++++++++++++++++++++++++++
thanks for any help
