mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 11:24:46 +00:00
41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace BehaviorTreeSlayer
|
|
{
|
|
public class MoveTo : ActionNode
|
|
{
|
|
[OutField]
|
|
public string ItemName;
|
|
[OutField]
|
|
public Vector3 Pos;
|
|
[OutField]
|
|
public float Speed;
|
|
GameObject obj;
|
|
float s;
|
|
[ShowMe("Time {0:F2}")]//You can use string to show infomation on nodeview
|
|
float t;
|
|
Vector3 startPos;
|
|
public override void Enter(object args)
|
|
{
|
|
BehaviorTree behaviorTree = args as BehaviorTree;
|
|
obj = behaviorTree[ItemName] as GameObject;
|
|
startPos = obj.transform.position;
|
|
s = Vector3.Distance(Pos, startPos) / Speed;
|
|
t = 0;
|
|
}
|
|
public override TaskResult Tick(double dt, object args = null)
|
|
{
|
|
t += (float)dt;
|
|
obj.transform.position = Vector3.Lerp(startPos, Pos, t / s);
|
|
if (t > s)
|
|
{
|
|
return TaskResult.OK;
|
|
}
|
|
else
|
|
{
|
|
return TaskResult.Running;
|
|
}
|
|
}
|
|
}
|
|
}
|