You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
45 lines
1.5 KiB
using UnityEngine;
|
|
|
|
public class IVMateChasePlayer : State<IVMate>
|
|
{
|
|
IVCharacter player;
|
|
|
|
float pow2MinDistToPlayer;
|
|
|
|
public void Setup(IVCharacter player)
|
|
{
|
|
this.player = player;
|
|
pow2MinDistToPlayer = GameProperty.Instance.DistRangeMateToPlayer.x * GameProperty.Instance.DistRangeMateToPlayer.x;
|
|
}
|
|
|
|
public override void Enter()
|
|
{
|
|
Debug.Assert(Owner.Excutor.SkeletonAnimation != null && Owner.Excutor.SkeletonAnimation.TryGetAnimation("move", out Spine.Animation _), "SkeletonAnimation is null or move animation not exist");
|
|
Owner.Excutor.SkeletonAnimation.AnimationState.SetAnimation(0, "move", true);
|
|
}
|
|
|
|
public override void Excute()
|
|
{
|
|
if(IsPlayerTooNear())
|
|
{
|
|
Owner.ChangeState<IVMateIdle>();
|
|
}
|
|
else
|
|
{
|
|
Vector2 dir = player.transform.position - Owner.Excutor.transform.position;
|
|
dir.Normalize();
|
|
|
|
Vector3 newPosition = (Vector2)Owner.Excutor.transform.position + (dir * Owner.Excutor.Data.DefaultMoveSpeed * Time.unscaledDeltaTime);
|
|
newPosition.z = Owner.Excutor.transform.position.z;
|
|
|
|
Owner.Excutor.transform.position = newPosition;
|
|
Owner.Excutor.ChangeLookDirection(player.transform);
|
|
}
|
|
}
|
|
|
|
bool IsPlayerTooNear()
|
|
{
|
|
float sqrtDist = Vector2.SqrMagnitude(Owner.Excutor.transform.position - player.transform.position);
|
|
return sqrtDist <= pow2MinDistToPlayer;
|
|
}
|
|
}
|