chore: initial commit
This commit is contained in:
41
Assets/Scripts/Enemies/AI/BD_MoveToPlayer.cs
Normal file
41
Assets/Scripts/Enemies/AI/BD_MoveToPlayer.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:移向玩家。
|
||||
/// OnStart 缓存玩家 Transform,OnUpdate 每帧更新导航目标。
|
||||
/// </summary>
|
||||
public class BD_MoveToPlayer : Action
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
private Transform _playerTransform;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_enemy = GetComponent<EnemyBase>();
|
||||
var playerGO = GameObject.FindWithTag("Player");
|
||||
if (playerGO != null) _playerTransform = playerGO.transform;
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
if (_playerTransform == null) return TaskStatus.Failure;
|
||||
|
||||
_enemy.MoveTo(_playerTransform.position);
|
||||
_enemy.FacePlayer();
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
_enemy?.StopMovement();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user