Hello! Im currently busy with making kinda slot machine. I have a cilinder which has an animation where it rotates within 6 frames, each frame adds 60 degrees to the rotation and represents certain picture on the cilinder. What I want to do is to push one button to start spinning the disk (done) and another one to stop the spinning animation on a random frame. And it must be perfectly aligned in order to see the random result clearly. What is the best way to do so?
Your question gave me a good excuse to play with animations which I’ve only used on a superficial level. Contrary to the many UA posts on pausing animations and setting the animation time, I was not able to freeze the animation on a specific time/frame. That is, the animation state reported the correct time, but the visual did not match. So here is a brute force solution of simply setting the rotation:
var minSpinTime = 2.8;
var maxSpinTime = 3.2;
function Start() {
animation["cylanim"].wrapMode = WrapMode.Loop;
}
function Update () {
if (Input.GetKeyDown(KeyCode.Space)) {
animation.Play();
Invoke("StopWheel", Random.Range(minSpinTime, maxSpinTime));
}
}
function StopWheel() {
animation.Stop();
transform.rotation = Quaternion.Euler(Random.Range(0,6) * 60.0, 0.0, 90.0);
}