• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by carter-carl30 · Jun 30, 2016 at 06:42 PM · animationrotation360-degrees

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Asgardr · Jun 30, 2016 at 07:09 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

109 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make a sprite animation rotate towards the cursor? 0 Answers

Help with 2nd arm sprite rotation 1 Answer

Blend Tree animation problems at rotation 1 Answer

Rotate the player with animation 2 Answers

How to flip euler angle without flipping axis 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges