Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

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

Alpha Layer Fade To Black Animation On an Inverted Sphere? 0 Answers

Animator and code controlled bone rotations 0 Answers

Free Look Camera Rig Changing Rotation 1 Answer

Starting animation on specific time (%) with scene preview? 0 Answers

Odd twitching when using deltaTime 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges