I am working on a simple animation for my UI elements.
I have an animator component which has 2 different animations - ZoomIn and ZoomOut.
These animations are displayed whenever an UI element (e.g. Button) needs to be displayed on the screen.
I normally prefer deactivating the gameobject when not displaying.
I have written the following method for the animations:
private IEnumerator ToggleObjectWithAnimation (GameObject gameObj) {
Animator gameObjectAnimator = gameObj.GetComponent (); // Animator is set to unscaled time
if (gameObj.activeSelf == false) {
gameObj.transform.localScale = new Vector3 (0, 0, 1.0f);
gameObj.SetActive (true);
gameObjectAnimator.SetTrigger ("ZoomIn");
yield return new WaitForSeconds (0.5f);
} else if(gameObj.activeSelf == true) {
gameObjectAnimator.SetTrigger ("ZoomOut");
yield return new WaitForSeconds (0.5f);
gameObj.SetActive (false); // code not execute when timescale = 0
}
yield return null;
}
The code works fine when for most of the screens, but shows problem when I pause the game using timescale = 0.
When timescale is 0, the line gameObj.SetActive (false) does not work.