- Home /
Question by
rossoserous · May 11 at 12:13 PM ·
array
Find Gameobjects from array that have a double value "elo" between two numbers.
I am trying to make a matchmaking system, and I have an array of Gameobjects PlayersInque. each of those players has a script that contains their Elo.
I have code that is able to find a random Player from the array right now. but I would like to be able to only search from the players that are between for example 1000-1200 Elo. In order to make balanced que times. Sorry I am new to Unity and c#, I cant find a solution anywhere.
public void QueueDecider()
{
// Array of all players In Queue
PlayersInque = GameObject.FindGameObjectsWithTag("InQueue");
//finds a random player from Array
randomnumberA = Random.Range(0, PlayersInque.Length);
PPlayerA = PlayersInque[randomnumberA];
PlayerA = PPlayerA;
if (PlayerA == null)
{
PlayerA.gameObject.tag = "InQueue";
Destroy(gameObject);
}
PlayerA.transform.gameObject.tag = "GameFound";
// next player, but instead of getting a random object from the array I need it to find one that has a similar Elo to PlayerA
randomnumberB = Random.Range(0, PlayersInque.Length);
PPlayerB = PlayersInque[randomnumberB];
PlayerB = PPlayerB;
//stops vsing player vsing themselves
if (PlayerB == PlayerA)
{
Destroy(gameObject);
}
if (PlayerB == null)
{
PlayerB.gameObject.tag = "InQueue";
Destroy(gameObject);
}
PlayerB.transform.gameObject.tag = "GameFound";
}
sorry if this is unclear
Comment
Your answer
Follow this Question
Related Questions
Call Methods from inactive GameObjects 1 Answer
Access Animations array in Animation component 1 Answer
Calling an object from Array/List 1 Answer
Array copy 2 Answers
I need some help accessing an array from another script 1 Answer