I have an object that is supposed to toggle between glowing or not glowing on anyKeyDown. To toggle between my states (large/small halo size and light/dark emission colour) I have an animator using variables from a script, with 3 animations: glow (gradually increase the halo size and emission colour) pale (the opposite), and idle (some passive idle movement). The transitions between the states are like this:
and my script is as follows
public class glowControl : MonoBehaviour {
MeshRenderer MR;
Animator A;
public bool transitionPlay = false;
public bool glowing = false;
public Color notGlowingColour;
public Color glowingColour;
public float colourScale;
void Start () {
A = this.GetComponent<Animator> ();
MR = this.GetComponent<MeshRenderer> ();
}
void Update () {
if (Input.anyKeyDown) {
glowing = !glowing;
transitionPlay = true;
}
A.SetBool ("Transition Play", transitionPlay);
A.SetBool ("Glowing", glowing);
MR.material.SetColor ("_EmissionColor", Color.Lerp(notGlowingColour, glowingColour, colourScale)); //Set the colour of emission
}
}
So what I’ve tried to do is at the end of the pale and glow animations is to set transitionPlay to false, and set the condition for either of them to return to idle as that transitionPlay must be false (so that once the animation is complete, the object returns to idling). The condition to change from idle to either glow or pale is that transitionPlay must be true (which happens on anyKeyDown in the script) and that glowing is either true or false respectively (which gets toggled every anyKeyDown).
So I thought that this should work fine, but what actually happens when I play is that the object starts halfway between glowing and not glowing (halo size and colourScale half of what they should be when glowing) and on anyKeyDown, the objects flickers (looping the glow and pale animations of the object transitioning) for a bit and then returns to be halfway between the states.
If anyone has any idea what I’m doing wrong then please bless me with your knowledge.