IndieGame/client/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/Movement/Pathfinding/FindClosestEdge.cs

33 lines
888 B
C#
Raw Normal View History

2024-10-11 10:12:15 +08:00
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
using NavMesh = UnityEngine.AI.NavMesh;
using NavMeshHit = UnityEngine.AI.NavMeshHit;
namespace NodeCanvas.Tasks.Actions
{
[Name("Find Closest NavMesh Edge")]
[Category("Movement/Pathfinding")]
[Description("Find the closes Navigation Mesh position to the target position")]
public class FindClosestEdge : ActionTask
{
public BBParameter<Vector3> targetPosition;
[BlackboardOnly]
public BBParameter<Vector3> saveFoundPosition;
private NavMeshHit hit;
protected override void OnExecute() {
if ( NavMesh.FindClosestEdge(targetPosition.value, out hit, -1) ) {
saveFoundPosition.value = hit.position;
EndAction(true);
return;
}
EndAction(false);
}
}
}