59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using UnityEngine;
|
|
|
|
public class EnemyAI : Character
|
|
{
|
|
protected override void SetClimbingAnimation(bool isClimbing)
|
|
{
|
|
}
|
|
|
|
protected override void SetWalkingAnimation(bool isWalking)
|
|
{
|
|
_animator.SetBool("Walk",isWalking);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
float horizontal = 0;
|
|
float vertical = 0;
|
|
|
|
Vector2 directionToPlayer = Player.Instance.transform.position - transform.position;
|
|
directionToPlayer.Normalize();
|
|
|
|
float verticalDistance = Player.Instance.transform.position.y - transform.position.y;
|
|
|
|
|
|
if (verticalDistance > 0.1f && isCanClimbUp && isAllowVertical)
|
|
{
|
|
vertical = VerticalMove(verticalDistance);
|
|
}
|
|
else if (verticalDistance < 0f && isAllowVertical && isCanGoDown)
|
|
{
|
|
vertical = VerticalMove(verticalDistance);
|
|
}
|
|
else
|
|
{
|
|
if (Mathf.Abs(Player.Instance.transform.position.x - transform.position.x) < 0.1f)
|
|
{
|
|
horizontal = 0;
|
|
}
|
|
else if (directionToPlayer.x < 0)
|
|
{ horizontal = -1; }
|
|
else if (directionToPlayer.x > 0)
|
|
{ horizontal = 1; }
|
|
|
|
}
|
|
|
|
if (Input.GetKey(KeyCode.T))
|
|
{ vertical = 1; }
|
|
if (Input.GetKey(KeyCode.G))
|
|
{ vertical = -1; }
|
|
base.MoveTo(horizontal, vertical);
|
|
}
|
|
|
|
private float VerticalMove(float verticalDistance)
|
|
{
|
|
float verticalDirection = Mathf.Sign(verticalDistance);
|
|
return verticalDirection;
|
|
}
|
|
}
|