Hello, in the project I am working on I am trying to instantiate these “recruits” off-screen and have them walk into the screen but to a random spot designated by an array of transforms. Therefore, I am trying to make a random number generator that does not repeat numbers, until it hits the max number of transforms I have placed. Once it can no longer give the “recruit” a special number, I want the used number list to clear and start the process over. In my current form of this code, it will overlap numbers without ever clearing the list and I am not really sure why. I am open to the idea that I am approaching this issue the wrong way, and would love any advice or code fixes. Thank you in advance. Here is the relevant code, and I will be watching this thread if you have any questions that might help you help me.
The code here is located on my game controller, independent of the recruits themself.
public Transform[] recruitMoveTo;
public List<int> usedRecruitMovePoints = new List<int>();
public int RecruitMoveTo()
{
int MoveTo;
MoveTo = RollMoveRecruit();
if (usedRecruitMovePoints.Count == recruitMoveTo.Length)
{
Debug.Log("List cleared");
ClearUsedRecruitList();
}
if (usedRecruitMovePoints.Contains(MoveTo))
{
while (usedRecruitMovePoints.Contains(MoveTo))
{
MoveTo = RollMoveRecruit();
}
}
else
{
usedRecruitMovePoints.Add(MoveTo);
}
Debug.Log(MoveTo);
return MoveTo;
}
private int RollMoveRecruit()
{
int x;
x = Random.Range(0, recruitMoveTo.Length);
return x;
}
I am calling this function on a script attached to the recruit’s gameobject.
if (myTeam == teams[2])
{
agent.SetDestination(gameController.recruitMoveTo[gameController.RecruitMoveTo()].position);
}
Thanks again for any help or ideas.