Hello, I’m trying to create a simple pause menu, while the game is paused I set the Time.timeScale to zero, which pauses everything wonderfully. However I noticed that a few of my button animations are running incorrectly?
// Pause Controller
if (Input.GetKeyDown(KeyCode.Escape))
{
// Paused, or unpaused
pauseMenu.GetComponent<PauseMenuScript>().Display = !pauseMenu.GetComponent<PauseMenuScript>().Display;
pauseMenu.SetActiveRecursively(pauseMenu.GetComponent<PauseMenuScript>().Display);
if (pauseMenu.GetComponent<PauseMenuScript>().Display)
{
// Paused
Time.timeScale = 0;
}
else
{
// Remove menu, and re-enable the players, laptimer, etc....
Time.timeScale = 1;
}
}
// End Pause Controller
That is the logic that pauses my game.
The script that handles the button animations looks like this:
using UnityEngine;
using System.Collections;
public class btnAnim : MonoBehaviour
{
public AnimationClip onAnim;
void OnMouseEnter() {
animation.AddClip(onAnim, "on");
animation["on"].speed = 1.0F;
animation.Play("on");
}
void OnMouseExit() {
animation["on"].speed = -1.0F;
animation["on"].time = animation["on"].length;
animation.Play("on");
}
void OnMouseUp() {
gameObject.SendMessage("onClick", SendMessageOptions.DontRequireReceiver);
}
}
This script takes the button it is attached to and makes it slowly appear brighter when it is moused over due to the animation I’m using. It works fine for all the other buttons through out the game perfectly until I display the pause menu when the Time.timeScale = 0. If I drag my pause menu prefab into a empty scene it works fine. So I was wondering if it was the Time.timeScale = 0 that’s making my animation look like its running backwards or if it was something else entirely.
What I mean by backwards is on mouse over the first time nothing happens, and then when you leave the button it animates the mouse over animation and when you go back it animates the on mouse leave animation.
Thanks in advance,
Hans