mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-27 03:44:54 +00:00
41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
|
using HPJ.Presentation.Agents;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace HPJ.Presentation
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Am Example script to display the local avoidance feature
|
||
|
/// </summary>
|
||
|
public class LocalAvoidanceSceneScript : MonoBehaviour
|
||
|
{
|
||
|
public Transform StartTransform;
|
||
|
public Transform EndTransform;
|
||
|
public NavigationAgent AgentPrefab;
|
||
|
|
||
|
private NavigationAgent _firstAgent;
|
||
|
|
||
|
private bool _direction = false;
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
_firstAgent = Instantiate(AgentPrefab, StartTransform.position, Quaternion.identity);
|
||
|
_firstAgent.OnMovingComplete.AddListener(RepeatDestination);
|
||
|
_firstAgent?.GroundCast?.TeleportUp();
|
||
|
_firstAgent.SetDestination(EndTransform.position);
|
||
|
}
|
||
|
|
||
|
private void RepeatDestination(NavigationAgent Agent)
|
||
|
{
|
||
|
if (_direction)
|
||
|
{
|
||
|
Agent.SetDestination(EndTransform.position);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Agent.SetDestination(StartTransform.position);
|
||
|
}
|
||
|
_direction = !_direction;
|
||
|
}
|
||
|
}
|
||
|
}
|