animation 360 rotation

hi all, I am trying to make a fruit machine, i have 3 cylinders, I have made an animation that rotates the cylinders 360 degrees on the x axis over 1:00 in the animation editor (sample rate 60).

currently all the cylinders have the same animation to test.

what I am doing is having a button that you press that then enables the animator to spin the cylinders this is my script :

#pragma strict
private var ray : Ray;
private var rayCastHit : RaycastHit;
var mySound: AudioClip;
var reel_1 : GameObject;
var reel_2 : GameObject;
var reel_3 : GameObject;
var rotateSpeed = 5; 

function OnMouseUp () {

//play sound
audio.clip = mySound;
audio.Play();

StartCoroutine("Spin");	

	}
	
function Spin(){

	reel_1.GetComponent(Animator).enabled = true;
	reel_2.GetComponent(Animator).enabled = true;
    reel_3.GetComponent(Animator).enabled = true;
    
    yield WaitForSeconds(1);
	
	//stop sound
	audio.Stop();
	reel_1.GetComponent(Animator).enabled = false;
	reel_2.GetComponent(Animator).enabled = false;
	reel_3.GetComponent(Animator).enabled = false;
}

when I press my spin button the reels spin fine, the problem I am having is that when they come to a stop, on each press they seem to stop at a slightly different position.

I want them to always stop in the same place (like on a slot machine).

Anyone see what I am doing wrong?

cheers

If you’re using an animator component, you shouldn’t be enabling and disabling it to start or stop an animation. There are built-in functions that you can call on the animator component. Namely, one called:

Animator.Play()

And here’s a video that might help you figure out how to work properly with the Animator component. I do recommend watching it. And this is the manual page for the Animator, which is a very good read too.

However, I would suggest you use state machine transitions to control the animations, instead of calling them directly like this. This also gives you flexibility for later.