Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by pudd1nG · Jan 12, 2015 at 02:54 PM · c#animationanimatorsprites

Manipulating 'Animator' speed to control animation / events

Hi!

I'm using a single animated sprite as an icon in our game world. Initially the animation sits with

 animator.speed = 0;

till the user hovers over it, at which point it sets

 animator.speed = 1;

I then have an animation event on the last frame of the animation, which sets

 ticked = true;

The first frame then checks if 'ticked' is true and if it is, pauses the animation with

 animator.speed = 0;

What then happens however, is immediately hovering over the sprite makes it first the event on the last frame on the animation. From what I can tell, it runs the last frames event as soon as you set the speed to 0.

Am I going about this wrong? The functionality I want is for the animation to play through to the end while the using is hovering, reverse to the beginning if they move away and run a function if they make it to the end of the animation. I thought what I had would work, but the events just seem to fire willy nilly.

Any help appreciated! Script below for reference.

 void Start() {
     animator = gameObject.GetComponent<Animator>();
     animator.speed = 0;
 }
 
 void Update() {
     RaycastHit hit;
     bool isLookedAt = GetComponent<Collider>().Raycast(head.Gaze, out hit, Mathf.Infinity);

     if (isLookedAt && !looked) //if icon is hovered and not yet playing, play
     {
         looked = true;
         animator.speed = 1;

     }
     else if (!isLookedAt && looked) //if icon is playing but no hovered, stop
     {
         looked = false;
         animator.speed = -1;

     }

 }

 void endTrigger() //event on the last frame of the animation
 {
     open.SetActive(true);
     ticked = true;
 }

 void checkTrigger() //event on the first frame of the animation
 {
     if (ticked) {
         animator.speed = 0;
         ticked = false;
     }
 }



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 wuzibu · May 27, 2015 at 10:35 AM

Seems like we're getting help with the release of 5.1 http://forum.unity3d.com/threads/mecanim-events-firing-incorectly-when-clip-is-playing-in-reverse-bug.226992/

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

26 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

Related Questions

Left and right running animations are different how do I set up the controls?,Left and Right running animations are different animations: How do I code this or what should I do? 0 Answers

Efficient way to instantiate a sprite that plays an animation then destroys itself? (3d space) 1 Answer

Animations out of sync? 0 Answers

How to make animation and change position at the same time ? ( Example , like MapleStory /Terraria Slime hoping from one place to another ) 0 Answers

How to swap sprites? 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