using System.Collections; using System.Collections.Generic; using UnityEngine; public class Bandit : Fighter { [SerializeField, Tooltip("When the AntiPlayer is closer than this value, change to a combat idle anim")] float playerNearDistance = 3.75f; [SerializeField, Tooltip("How close the AntiPlayer has to be in order for this Bandit to start attacking")] float playerDistanceToAttack = 1.25f; GameObject antiPlayer; protected override void Awake() { base.Awake(); antiPlayer = GameObject.FindGameObjectWithTag("AntiPlayer"); animator.SetBool("Grounded", true); } protected override void Update() { base.Update(); if (GetDistanceToAntiPlayer() < playerNearDistance) { animator.SetInteger("AnimState", 1); // Combat Idle } else { animator.SetInteger("AnimState", 0); // Idle } // animator.SetInteger("AnimState", 2); // Run // Always face the AntiPlayer spriteRenderer.flipX = transform.position.x < antiPlayer.transform.position.x; } protected override bool CanAttack() { return GetDistanceToAntiPlayer() < playerDistanceToAttack; } protected override void Attack() { animator.SetTrigger("Attack"); } float GetDistanceToAntiPlayer() { return Vector3.Distance(transform.position, antiPlayer.transform.position); } }