I am making a game which involves combat, and i wanted to make my enemy wander around. The best option that i have found was to store some empty gameobjects on some variables and make my enemy choose between them and follow one, but i don't know how to ramdomize it. How can i make my enemy choose between different variables? Something like this:
public GameObject location1;
public GameObject location2;
public GameObject location3;
public GameObject location4;
public GameObject location5;
public GameObject location6;
void Start()
{
StartCoroutine(FollowCoordinates());
}
void Update()
{
}
//This will set the target position for the NavmeshAgent from time to time.
IEnumerator FollowCoordinates()
{
while (true)
{
//This will set the target coordinates
GetComponent().SetDestination(?????.position); // The "?????" is where i want to make the random choice.
//Wait one second and then loop
yield return new WaitForSeconds(1);
}
}
}
Sorry for the giant amount of variables, i am new to C-Sharp.
↧