Hey everyone,
i’m kinda new on Unity and I’m trying to make a navmeshagent ( a spider) moving in a more or less natural way. So with a YT tuto I make a script for the spider to go to a trigger, which is randomly teleport to another position. And it’s work pretty fine. But the fact that the spider never stops his movement isn’t realistic at all.
So i’m searching a way to make my agent to wait a random time before going to the next destination.
I’ve read that I should use WaitforSecond and a Coroutine, but i’m not undestand how it works. Could somebody help me to do this please?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestinationChange : MonoBehaviour
{
public float xPos;
public float yPos;
public float zPos;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "NPC")
{
xPos = Random.Range(73, 63);
yPos = Random.Range((float)17.8, (float)17.9) ;
zPos = Random.Range(62, 58);
this.gameObject.transform.position = new Vector3(xPos, yPos, zPos);
}
}
}