Check if animation is playing on button click
Dear forum,
I have two animation clips (Rabbit_in and rabbit_loop), which are connection by a transition from Rabbit_in to rabbit_loop. I also have a game object with this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class rabbit_anim_controller : MonoBehaviour
{
public Animator anim;
void Start()
{
anim = GetComponent<Animator>();
if (anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 1)
{ //If normalizedTime is 0 to 1 means animation is playing, if greater than 1 means finished
Debug.Log("not playing");
}
else
{
Debug.Log("playing");
}
}
}
I trigger these by clicking a button that has a on click() referring to the game object and uses the "Animator.Play" and refers to the string "rabbit_in".
Now, once the button is clicked the animation starts and goes to the loop phase. But I want to click the button several times as there is another on click on it that does some external calculation.
Is it possible to sneak an If function in there that keeps the rabbit_loop looping even if the button is clicked? It can´t be that difficult but I can´t get my head around, as I´m too tired as my toddler daughter has been crying all night due to her teething X(.
Thank you for your time