Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Gary 2 · Jan 21, 2011 at 08:21 AM · animationreverse

HELP!! Animation wont reverse..

Hi all,

followed the forums & answers, but i still could get it run animation in reverse... animation was done in unity, everytime i run, it would only run the 1st step, then when i click again, supposely it should reverse but it repeated again...

any ideas anyone?

Thanks

animation.Stop();

function Update () {

 if (Input.GetMouseButtonDown(0))
 {
     var hit : RaycastHit;
     var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

     if (Physics.Raycast(ray, hit))
     {
         hit.collider.gameObject.animation["slot1"].time=0.0;
         hit.collider.gameObject.animation["slot1"].speed=1.0;
         hit.collider.gameObject.animation.Play ("slot1");
         //hit.collider.gameObject.animation.Stop ("slot1");

         Debug.Log("open "+hit.collider.name);
     }
 }

 else if (Input.GetMouseButtonDown(0))
 {

     //if (Physics.Raycast(ray, hit))
     //{

         hit.collider.gameObject.animation["slot1"].speed=-1.0;
         hit.collider.gameObject.animation["slot1"].time = hit.collider.gameObject.animation["slot1"].length;
         hit.collider.gameObject.animation.Play("slot1");
         //hit.collider.gameObject.animation["slot1"].time=0;
         //hit.collider.gameObject.animation["slot1"].speed=1;
         //hit.collider.gameObject.animation.Play ("slot1");
         Debug.Log("close "+hit.collider.name);

     //}

 }
 }

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
Best Answer

Answer by DaveA · Jan 21, 2011 at 08:28 AM

You're testing for the same mouse event in the same frame. I think you need a boolean or something, toggle that, and depending on current value, run the anim forward or backward.

Something like this:

var forward = true; function Update () {

 if (Input.GetMouseButtonDown(0)) // user has pressed left mouse button
 {
     var hit : RaycastHit;
     var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

     if (Physics.Raycast(ray, hit)) // hit object
         forward = !forward;  // reverse direction

     if (forward)
     {
         hit.collider.gameObject.animation["slot1"].time=0.0;
         hit.collider.gameObject.animation["slot1"].speed=1.0;
         hit.collider.gameObject.animation.Play ("slot1");
         Debug.Log("open "+hit.collider.name);
     }
     else // backward
     {
         hit.collider.gameObject.animation["slot1"].speed=-1.0;
         hit.collider.gameObject.animation["slot1"].time = hit.collider.gameObject.animation["slot1"].length;
         hit.collider.gameObject.animation.Play("slot1");
         Debug.Log("close "+hit.collider.name);

     }

}

Comment
Add comment · Show 5 · 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
avatar image Gary 2 · Jan 21, 2011 at 09:54 AM 0
Share

ehh.... actually, i want to left to run then left click to reverse, how should i do so?

avatar image DaveA · Jan 21, 2011 at 05:10 PM 0
Share

Edited my answer to illustrate (code not tested)

avatar image rahulpatil6220375 DaveA · Mar 08, 2019 at 12:16 PM 0
Share

animation will be run one time when button click??

avatar image Gary 2 · Jan 22, 2011 at 06:32 AM 0
Share

not tested but it works! thanks

avatar image Gary 2 · Jan 22, 2011 at 06:35 AM 0
Share

let's say for example, i got 3 slots are same on X,Y axis but different on Zaxis. my qn: is that how do i do it if user click on slot1, but disable raycast on slot2 & 3? then click on slot2, disable 1&3?

thanks again

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

1 Person is following this question.

avatar image

Related Questions

Nav mesh agent moves backwards - How can I rotate gameobject without using an empty 1 Answer

How to Record or Play an animation backwards 1 Answer

Why is Animation Not Playing in Reverse? 2 Answers

Unity 5. Reverse animation play ? 4 Answers

Reverse animation problem 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