SHADE_Y3/Assets/Scripts/Gameplay/AIBehaviour/AIRework/NavigationTestScript.cs

53 lines
1.3 KiB
C#
Raw Normal View History

2023-03-24 04:22:51 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SHADE;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
2023-03-24 04:22:51 +08:00
public class NavigationTestScript :Script
{
public GameObject endPoint;
public float speed = 1.0f;
float timer = 0.0f;
2023-03-24 04:22:51 +08:00
protected override void start()
{
Navigation nav = GetComponent<Navigation>();
Transform endTransform = endPoint.GetComponent<Transform>();
if (endTransform)
nav.MoveTo(endTransform.GlobalPosition);
2023-03-24 04:22:51 +08:00
}
protected override void update()
{
timer += Time.DeltaTimeF;
2023-03-24 04:22:51 +08:00
Navigation nav = GetComponent<Navigation>();
Transform transform = GetComponent<Transform>();
if (timer >= 1.0f)
2023-03-24 04:22:51 +08:00
{
timer = 0.0f;
2023-03-24 04:22:51 +08:00
Transform endTransform = endPoint.GetComponent<Transform>();
if (endTransform)
2023-03-24 04:22:51 +08:00
nav.MoveTo(endTransform.GlobalPosition);
}
if (nav && transform)
{
2023-03-24 04:22:51 +08:00
transform.LocalPosition = transform.LocalPosition + ( nav.GetForward() * Time.DeltaTimeF * speed);
2023-03-24 13:26:18 +08:00
2023-03-24 04:22:51 +08:00
}
}
}
}