Hi everyone.
I have an object that every time when I press it start the animation (flapping wings).
I would like to add a second animation: “YellowBoom”, which would replace the previous one only for 5 seconds after the collision with the object “GoldWorm”.
After 5 seconds, the animation should return to the original form.
How to change animations for only 5 seconds?
Below is my script that I wrote and I really don’t know what and where to add.
I would be grateful for help, because it took a little to write this script and I would not like to smash it ![]()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerBehaviour : MonoBehaviour {
public Transform mesh;
public float forceFly = 100;
private Animator animatorPlayer;
private float currentTimeToAnim;
private bool inAnim;
// Use this for initialization
void Start () {
animatorPlayer = mesh.GetComponent<Animator>();
this.gameObject.GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0))
{
GetComponent<AudioSource>().Play();
inAnim = true;
GetComponent<Rigidbody2D> ().velocity = Vector2.zero;
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, -1) * forceFly);
}
if (inAnim) {
currentTimeToAnim += Time.deltaTime;
if (currentTimeToAnim > 0.4f) {
currentTimeToAnim = 0;
inAnim = false;
}
}
animatorPlayer.SetBool ("callFly", inAnim);
}
void OnCollisionEnter2D(Collision2D coll){
if (coll.gameObject.tag == ("Enemy"))
Destroy (gameObject);
{
if (coll.gameObject.tag == ("GoldWorm")) {
forceFly = 250;
StartCoroutine (FiveSecondsCooldown ());
}
else {
if (coll.gameObject.tag == ("Hook")) {
forceFly = 5;
StartCoroutine (FiveSecondsCoolUp ());
}
}
}
}
public IEnumerator FiveSecondsCooldown() {
forceFly = 250;
yield return new WaitForSeconds(5f); //
forceFly = 100;
}
public IEnumerator FiveSecondsCoolUp() {
forceFly = 5;
yield return new WaitForSeconds(5f); //
forceFly = 100;
}
}