You've already forked taptap2024_GJ_chidouren
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
namespace Game.Component.EnemyFSM_AI
|
|
{
|
|
public class RandomWalk : EnemyFSMState
|
|
{
|
|
private Vector2 target;
|
|
public override void OnEnter ()
|
|
{
|
|
this.Entity.AnimState.SetState (EnemyAnimStateType.Walk);
|
|
this.target = this.CreateRandomPos ();
|
|
this.SetAiTarget (this.target);
|
|
}
|
|
|
|
public override void OnUpdate ()
|
|
{
|
|
if (Vector2.Distance (this.Entity.transform.position, this.target) < 0.5f)
|
|
{
|
|
this.target = this.CreateRandomPos ();
|
|
this.SetAiTarget (this.target);
|
|
}
|
|
}
|
|
|
|
private Vector2 CreateRandomPos ()
|
|
{
|
|
var point = this.Entity.CreatePos;
|
|
var area = this.Entity.WalkArea.Abs ();
|
|
//随机生成一个位置
|
|
var x = Random.Range(point.x - area.x / 2, point.x + area.x / 2);
|
|
var y = Random.Range(point.y - area.y / 2, point.y + area.y / 2);
|
|
return new Vector2(x, y);
|
|
}
|
|
}
|
|
} |