I have this script:
public class RandomMovement : MonoBehaviour
{
public NavMeshAgent agent;
public float range;
public Transform centrePoint;
void Start()
{
agent = GetComponent();
}
void Update()
{
if(agent.remainingDistance <= agent.stoppingDistance)
{
Vector3 point;
if (RandomPoint(centrePoint.position, range, out point))
{
Debug.DrawRay(point, Vector3.up, Color.blue, 1.0f);
agent.SetDestination(point);
}
}
}
bool RandomPoint(Vector3 center, float range, out Vector3 result)
{
Vector3 randomPoint = center + Random.insideUnitSphere * range;
NavMeshHit hit;
if (NavMesh.SamplePosition(randomPoint, out hit, 1.0f, NavMesh.AllAreas))
{
result = hit.position;
return true;
}
result = Vector3.zero;
return false;
}
}
And I want to add a bool thats a *chase* and if it is false then that thing happens but if its true, then the destination is set as the player. I tried a few ways, but they all break the code up.
Is it possible, or do I have to use another script with it already?
↧