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 /
avatar image
0
Question by pudd1nG · Mar 29, 2016 at 01:57 PM · c#animationsprite

Reversing a sprite animation

I have a project I'm trying to get working correctly in Unity 5. I've managed everything except this one this. Frustrating that it was so easy in Unity 4 and now seems like a complete mess to achieve.

I have a sprite animation that plays when the user looks at the sprite, if the user looks away before the sprite animation completes, it reverses it (using speed = -1) and plays back to the first frame. If the user plays the entire animation, the scene changes via an animation event trigger.

Now it seems in Unity 5, you cannot use speed = -1 to reverse an animation. Below is my script:

 using UnityEngine;
 using System.Collections;

 [RequireComponent(typeof(Collider))]
 public class LookTrigger : MonoBehaviour {
 private CardboardHead head;
 private Animator animator;

 public bool ticked = false;

 public bool looked = false;

 public GameObject open;


 void Start() {
     head = Camera.main.GetComponent<StereoController>().Head;
     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)
     {
         looked = true;
         animator.speed = 1;

     }
     else if (!isLookedAt && looked)
     {
         looked = false;
         animator.speed = 0;
         
     }

 }

 void EndTrigger(){
     if(animator.speed == 1){
         open.SetActive(true);
         animator.speed = 0;
         this.gameObject.SetActive(false);
     }
 }



  }


This worked so well in Unity 4, I'm not sure what to do to get it working the same in Unity 5. Any help appreciated! I tried looking into the animation state system, and setup 2 sprites (one reverse, one forward) and can get them to change, however I can't find a way to sync the frame the user looked away from the sprite, to have it seamlessly play in reverse. Why has this become so complicated?

Comment
Add comment · Show 1
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
avatar image Cherno · Mar 30, 2016 at 01:58 AM 0
Share

It should still be possible to use Speed -1. Nevertheless, you can also declare a new float variable parameter in the Animator inspector, and use this as the modifier of an AnimationState's speed. If you set teh variable to -1, the speed will be reversed as well.

Edit: Tested Speed -1 and it works as intended.

0 Replies

· Add your reply
  • Sort: 

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

145 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 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 can I call an animation via script? 1 Answer

Recoloring animated sprites [Solved] 2 Answers

Distribute terrain in zones 3 Answers

How to make Animated GUI element. 1 Answer

Switching between two blend trees,How do I change Entry to other blend tree 0 Answers


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