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.