UnityGame/Library/PackageCache/com.unity.ai.navigation/Samples~/Scripts/RandomWalk.cs
2024-10-27 10:53:47 +03:00

28 lines
674 B
C#

using UnityEngine;
using UnityEngine.AI;
namespace Unity.AI.Navigation.Samples
{
/// <summary>
/// Walk to a random position and repeat
/// </summary>
[RequireComponent(typeof(NavMeshAgent))]
public class RandomWalk : MonoBehaviour
{
public float m_Range = 25.0f;
NavMeshAgent m_Agent;
void Start()
{
m_Agent = GetComponent<NavMeshAgent>();
}
void Update()
{
if (m_Agent.pathPending || !m_Agent.isOnNavMesh || m_Agent.remainingDistance > 0.1f)
return;
m_Agent.destination = m_Range * Random.insideUnitCircle;
}
}
}