mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
@@ -18,22 +18,38 @@ namespace Pathfinding {
|
||||
public Transform target;
|
||||
IAstarAI ai;
|
||||
|
||||
void OnEnable () {
|
||||
public Vector3 pos;
|
||||
|
||||
void OnEnable ()
|
||||
{
|
||||
this.pos = this.transform.position;
|
||||
ai = GetComponent<IAstarAI>();
|
||||
// Update the destination right before searching for a path as well.
|
||||
// This is enough in theory, but this script will also update the destination every
|
||||
// frame as the destination is used for debugging and may be used for other things by other
|
||||
// scripts as well. So it makes sense that it is up to date every frame.
|
||||
if (ai != null) ai.onSearchPath += Update;
|
||||
if (ai != null) ai.onSearchPath += OnUpdate;
|
||||
}
|
||||
|
||||
void OnDisable () {
|
||||
if (ai != null) ai.onSearchPath -= Update;
|
||||
if (ai != null) ai.onSearchPath -= OnUpdate;
|
||||
}
|
||||
|
||||
/// <summary>Updates the AI's destination every frame</summary>
|
||||
void Update () {
|
||||
if (target != null && ai != null) ai.destination = target.position;
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
this.OnUpdate();
|
||||
}
|
||||
|
||||
public void SetTarget(Vector3 pos)
|
||||
{
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public void OnUpdate()
|
||||
{
|
||||
if (ai != null) ai.destination = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user