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 Ekta-Mehta-D · Aug 21, 2015 at 07:44 AM · animationunity 5animatortimerreverse

Reverse animation problem

Hii

I am working on reverse animation but some conditions are not satisfied to work as i wanted.

I am having one scale animation for x axis. Now i have empty state as default.

  • Next state is scale animation .

  • Transition between this two state is having one boolean parameter that is trigger.

  • On collisionenter i am making this "trigger" parameter to true so my animation will work.

  • Now i want this animation to work as reverse also so i have added one float parameter as "speed" which is set to 1.

  • and i have added this parameter as multiplier to speed.

  • Once simple scale animation is completed i want to start timer for 5 seconds and after 5 seconds i want same animation in reverse.

Code is here :

 using UnityEngine;
 using System.Collections;
 
 public class moveFlower : MonoBehaviour {
 
     float timer = 0.0f;
     bool timercheck = false;
     static float timeRemaining = 5.0f;
     GameObject plank;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         transform.Translate (Vector3.down * Time.deltaTime * 0.5f , Space.World);
 
         if(timercheck)
         {
             StartCoroutine("countDownTimer");
         }
 
 //        if(this.transform.position.y < -5.0f)
 //        {
 //            Destroy(this.gameObject);
 //        }
     }
 
     void OnCollisionEnter(Collision obj)
     {
 
         if(obj.gameObject.tag.Equals("platform"))
         {
 
             plank = obj.gameObject;
             obj.gameObject.GetComponent<Animator>().SetBool("trigger" , true);
             plank.gameObject.GetComponent<Animator>().SetFloat("speed" , 1.0f);
             this.gameObject.GetComponent<MeshRenderer>().enabled = false;
             timercheck = true;
 
         }
     }
 
     void countDownTimer()
     {
         if(timeRemaining < 0)
         {
             plank.gameObject.GetComponent<Animator>().SetBool("trigger" , true);
             plank.gameObject.GetComponent<Animator>().SetFloat("speed" , -1.0f);
             timercheck = false;
         }
         Debug.Log ("Time :" + timeRemaining);
         timeRemaining -= Time.deltaTime;
     }
 }
 

But next time scale animation is not working. Hope all you get idea,.

This script is attached to flower object and flower prefab are instantiated randomly.

Thanks.

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

Answer by Priyanshu · Aug 21, 2015 at 09:18 AM

One way is to make another Animation State. Assign it Scale animation. Set its speed to -1.

So basically there are 3 states :

  • Deault State (No animation)

  • Scale Up State (Scale animation), Speed = 1 and Non-looping.

  • Scale Down State (Scale Animation), Speed = -1 and Non-looping.

Inside OnCollisionEnter method, set transition from Default State to Scale Up State.

Inside CoundownTimer Coroutine, set transition from Scale Up State to Scale Down State

Assign exit time of 3rd transtion i.e. from Scale Down State to Default State to 1. This transitions animation to default state when Scale Down animation completes.

Comment
Add comment · Show 4 · 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 Ekta-Mehta-D · Aug 21, 2015 at 09:23 AM 0
Share

Ok but how to identify that scale down is completed ? can you please post some code ?

How to set exit time ?

avatar image Priyanshu · Aug 21, 2015 at 09:35 AM 0
Share

After scale down completes. Animation will automatically transit to default state due to exit time.

But if u want to identify enter/exit points off animation states. For that u will need Stat$$anonymous$$achineBehaviour scripts.

avatar image Ekta-Mehta-D · Aug 21, 2015 at 09:36 AM 0
Share

ok how can i set exit time ?

avatar image Positive7 · Aug 21, 2015 at 11:02 AM 0
Share

In Animator Window click on the transition arrow and in the Inspector you will see "Has Exit Time" bool

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

Button animator not playing. 0 Answers

Animator is not playing an AnimatorController 1 Answer

root motion on in place animation 0 Answers

Dynamic way to adjust animated sprite length 0 Answers

Check Animator State Animation Completed 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