So, my problem is that when the enemy chases the main character. When my character jumps on the high ground or just jumps, the enemy starts walking in the air. So here’s my code: I would like to know what else I can add to my code.
public class EnemyAl : MonoBehaviour
{
public Transform Target;
public float MoveSpeed;
public float AttackAnimDuration = 3f;
private bool paused = false;
public float speed = 3f;
private float attackTimer =0f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (!paused)
{
float move = MoveSpeed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, Target.position, move);
}
else
{
attackTimer += Time.deltaTime;
if(attackTimer >= AttackAnimDuration)
{
attackTimer = 0;
paused = false;
}
}
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player")
{
paused = true;
}
}
}