41 lines
1.0 KiB
C#
Raw Normal View History

2025-08-22 21:31:17 +05:00
using UnityEngine;
namespace UGUIMiniMap
{
public class bl_RandomBot : MonoBehaviour
{
[SerializeField] private float Radius = 50;
void FixedUpdate()
{
if (!Agent.hasPath)
{
RandomBot();
}
}
void RandomBot()
{
Vector3 randomDirection = Random.insideUnitSphere * Radius;
randomDirection += transform.position;
UnityEngine.AI.NavMeshHit hit;
UnityEngine.AI.NavMesh.SamplePosition(randomDirection, out hit, 75, 1);
Vector3 finalPosition = hit.position;
Agent.SetDestination(finalPosition);
}
private UnityEngine.AI.NavMeshAgent m_Agent;
private UnityEngine.AI.NavMeshAgent Agent
{
get
{
if (m_Agent == null)
{
m_Agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
}
return m_Agent;
}
}
}
}