Hello everyone, so I am remaking a classic game, in which a player approaches a bat enemy and the bat is supposed to exit its idle animation, enter an animation where it unfolds its wings, then it enters a final animation where it starts flapping its wings (and then flies towards the player). I’m having trouble finding out how to play the animation for the bat unfolding its wings once and then activating the flying animation which continues to loop, and once the bat starts flying it moves towards the player (I already have that line of code for the movement). I’m not sure if I have to code the one-time animation or if I can do it only in Unity’s Animation screen (I provided a pic of that below). Any help would be appreciated, thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BatController : MonoBehaviour {
Animator animator;
SpriteRenderer spriteRenderer;
public float speed; // speed that bat chases MegaMan
public float distBetween;
public float timeToAwake = 3f;
private Transform target; // holds the player
private bool isFlying;
private bool startTimer = false;
private float timer;
private void Awake()
{
timer = timeToAwake;
}
void Start () {
animator = GetComponent<Animator>();
animator.Play("Bat_idle");
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>(); // get player position
}
void Update () {
if (Vector2.Distance(transform.position, target.position) <= distBetween)
{
startTimer = true;
if (startTimer)
{
timer -= Time.deltaTime;
if (timer <= 0)
{
animator.Play("Bat_awake");
}
}
// transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime); // move bat, towards play pos, at certain speed
}
}
}