- Home /
How to change the lowest element in a list?
I wrote a script that would Instantiate gameobjects at a random spawnposition with lists. But now I want to get the element number, that contains the lowest number. I know that I can get the lowest value of multiple ones, but how to get the number of the element that contains the smallest amount?
private void Start()
{
WaveStart();
InvokeRepeating("Spawn", 10f, Random.Range(TimeSpan1, TimeSpan2));
}
private void Update()
{
if(Wave % 3 == 0)
{
TimeSpan1 = 0f;
TimeSpan2 = 0.5f;
}
}
void Spawn()
{
if (WaveStarted)
{
if (WavePoints == 0)
{
WaveStarted = false;
Invoke("WaveStart", 5);
}
if (Wave % 3 == 0)
{
int lowest = Mathf.Min(ZombsPerSpawn[1], ZombsPerSpawn[2], ZombsPerSpawn[3], ZombsPerSpawn[4], ZombsPerSpawn[5]);
}
else if (Wave % 3 != 0)
{
chosenSpawn = Random.Range(0, Spawns.Count);
}
ZombsPerSpawn[chosenSpawn] += 1;
if (WavePoints == 1)
{
GameObject cur1 = Instantiate(Zombies[0]);
WavePoints = 0;
cur1.transform.position = new Vector3(Spawns[chosenSpawn].position.x - 0f, Spawns[chosenSpawn].position.y + 0.6f, Spawns[chosenSpawn].position.z + 0.4f);
}
else if (WavePoints != 0)
{
chosenzombie = Random.Range(0, Zombies.Count);
if (WavePoints - Zombies[chosenzombie].GetComponent<PointsWorth>().Points >= 0)
{
GameObject Zomb = Instantiate(Zombies[chosenzombie]);
Zomb.transform.position = new Vector3(Spawns[chosenSpawn].position.x - 0f, Spawns[chosenSpawn].position.y + 0.6f, Spawns[chosenSpawn].position.z + 0.4f);
WavePoints -= Zomb.GetComponent<PointsWorth>().Points;
}
else
{
Spawn();
}
}
}
}
void WaveStart()
{
WaveStarted = true;
Wave += 1;
WavePoints = (int)Mathf.Pow(Wave, 2) + 10;
}
Comment
Answer by lelo_ · May 28 at 12:08 AM
As you can see in line 30, that only returned the value of the lowest element