So, a little hard to write a good title for this question but here goes:
I have a very simple animation, where the alpha value of a material goes from 0 to about 0.8. It’s pulsing, you might say. Until the animation is invoked, the value is 0. Also, the animation is set to
wrapMode = WrapMode.PingPong.
My problem is this: The animation is playing at the press of a button, and I want it to stop at the press of another button. But, I would really like it to stop when the alpha value returns to 0 and not just turn off at whatever value. This should make it look like it’s just dimming down and then disappearing when the second button is pressed, instead of just abruptly vanishing.
What i have tried so far is a basic
if(GameObject.renderer.material.color.a == 0) GameObject.animation.Stop();
The problem here is that as it’s being executed inside
OnGUI, the check is only being run once. Not good.
I’ve also tried changing the wrapMode to Once, but all this does is to play the animation forward from its current frame, and then stop at the last frame – which is 0.8 (not invisible as I want).
What I am basically looking for here is not so much scripting advice, but more some ideas for achieving what I want. don’t be shy – fire away…