You've already forked taptap2024_GJ_chidouren
init
This commit is contained in:
34
Assets/Scripts/Game/Component/EnemyFSM_AI/RandomWalk.cs
Normal file
34
Assets/Scripts/Game/Component/EnemyFSM_AI/RandomWalk.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component.EnemyFSM_AI
|
||||
{
|
||||
public class RandomWalk : EnemyFSMState
|
||||
{
|
||||
private Vector2 target;
|
||||
public override void OnEnter ()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user