Reverse animation problem


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(this.transform.position.y < -5.0f)
//		{
//			Destroy(this.gameObject);
//		}

	void OnCollisionEnter(Collision obj)


			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.


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.