I’m trying to simulate evolution where u get eliminated if ur score is the lowest. When I use the function Destroy(List[]) from some for me unknown reason it only destroys the first and the fift element in the list. Please help me! here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
public class Evolution : MonoBehaviour
{
public List<GameObject> Players;
public float timer;
public GameObject playerpre;
private GameObject player;
public float w1a, w2a, w3a, w4a, w5a, w6a, w7a, w8a, w9a, w10a, w11a, w12a, w13a, w14a, w15a, w16a;
public float w1b, w2b, w3b, w4b, w5b, w6b, w7b, w8b;
public float b11, b12, b13, b14, b21, b22;
// Start is called before the first frame update
void Start()
{
GetPlayerList();
}
// Update is called once per frame
void Update()
{
GetPlayerList();
Players = Players.OrderBy(Player => Player.GetComponent<AIMovement>().score).ToList();
timer += Time.deltaTime;
if (timer >= 15)
{
int i = 0;
while (i < 5)
{
Destroy(Players[0]);
Players.Clear();
Players.AddRange(GameObject.FindGameObjectsWithTag("Player"));
timer = 0f;
i++;
}
i = 0;
/*while (i < 5)
{
w1a = Players[0].GetComponent<AIMovement>().w1a;
w2a = Players[0].GetComponent<AIMovement>().w2a;
w3a = Players[0].GetComponent<AIMovement>().w3a;
w4a = Players[0].GetComponent<AIMovement>().w4a;
w5a = Players[0].GetComponent<AIMovement>().w5a;
w6a = Players[0].GetComponent<AIMovement>().w6a;
w7a = Players[0].GetComponent<AIMovement>().w7a;
w8a = Players[0].GetComponent<AIMovement>().w8a;
w9a = Players[0].GetComponent<AIMovement>().w9a;
w10a = Players[0].GetComponent<AIMovement>().w10a;
w11a = Players[0].GetComponent<AIMovement>().w11a;
w12a = Players[0].GetComponent<AIMovement>().w12a;
w13a = Players[0].GetComponent<AIMovement>().w13a;
w14a = Players[0].GetComponent<AIMovement>().w14a;
w15a = Players[0].GetComponent<AIMovement>().w15a;
w16a = Players[0].GetComponent<AIMovement>().w16a;
w1b = Players[0].GetComponent<AIMovement>().w1b;
w2b = Players[0].GetComponent<AIMovement>().w2b;
w3b = Players[0].GetComponent<AIMovement>().w3b;
w4b = Players[0].GetComponent<AIMovement>().w4b;
w5b = Players[0].GetComponent<AIMovement>().w5b;
w6b = Players[0].GetComponent<AIMovement>().w6b;
w7b = Players[0].GetComponent<AIMovement>().w7b;
w8b = Players[0].GetComponent<AIMovement>().w8b;
b11 = Players[0].GetComponent<AIMovement>().b11;
b12 = Players[0].GetComponent<AIMovement>().b12;
b13 = Players[0].GetComponent<AIMovement>().b13;
b14 = Players[0].GetComponent<AIMovement>().b14;
b21 = Players[0].GetComponent<AIMovement>().b21;
b22 = Players[0].GetComponent<AIMovement>().b22;
Destroy(Players[0]);
player = Instantiate(playerpre);
player.transform.position = new Vector3(0, -2.66f, 0);
player.GetComponent<AIMovement>().w1a = w1a;
player.GetComponent<AIMovement>().w2a = w2a;
player.GetComponent<AIMovement>().w3a = w3a;
player.GetComponent<AIMovement>().w4a = w4a;
player.GetComponent<AIMovement>().w5a = w5a;
player.GetComponent<AIMovement>().w6a = w6a;
player.GetComponent<AIMovement>().w7a = w7a;
player.GetComponent<AIMovement>().w8a = w8a;
player.GetComponent<AIMovement>().w9a = w9a;
player.GetComponent<AIMovement>().w10a = w10a;
player.GetComponent<AIMovement>().w11a = w11a;
player.GetComponent<AIMovement>().w12a = w12a;
player.GetComponent<AIMovement>().w13a = w13a;
player.GetComponent<AIMovement>().w14a = w14a;
player.GetComponent<AIMovement>().w15a = w15a;
player.GetComponent<AIMovement>().w16a = w16a;
player.GetComponent<AIMovement>().w1b = w1b;
player.GetComponent<AIMovement>().w2b = w2b;
player.GetComponent<AIMovement>().w3b = w3b;
player.GetComponent<AIMovement>().w4b = w4b;
player.GetComponent<AIMovement>().w5b = w5b;
player.GetComponent<AIMovement>().w6b = w6b;
player.GetComponent<AIMovement>().w7b = w7b;
player.GetComponent<AIMovement>().w8b = w8b;
player.GetComponent<AIMovement>().b11 = b11;
player.GetComponent<AIMovement>().b12 = b12;
player.GetComponent<AIMovement>().b13 = b13;
player.GetComponent<AIMovement>().b14 = b14;
player.GetComponent<AIMovement>().b21 = b21;
player.GetComponent<AIMovement>().b22 = b22;
player = Instantiate(playerpre);
player.transform.position = new Vector3(0, -2.66f, 0);
player.GetComponent<AIMovement>().w1a = w1a;
player.GetComponent<AIMovement>().w2a = w2a;
player.GetComponent<AIMovement>().w3a = w3a;
player.GetComponent<AIMovement>().w4a = w4a;
player.GetComponent<AIMovement>().w5a = w5a;
player.GetComponent<AIMovement>().w6a = w6a;
player.GetComponent<AIMovement>().w7a = w7a;
player.GetComponent<AIMovement>().w8a = w8a;
player.GetComponent<AIMovement>().w9a = w9a;
player.GetComponent<AIMovement>().w10a = w10a;
player.GetComponent<AIMovement>().w11a = w11a;
player.GetComponent<AIMovement>().w12a = w12a;
player.GetComponent<AIMovement>().w13a = w13a;
player.GetComponent<AIMovement>().w14a = w14a;
player.GetComponent<AIMovement>().w15a = w15a;
player.GetComponent<AIMovement>().w16a = w16a;
player.GetComponent<AIMovement>().w1b = w1b;
player.GetComponent<AIMovement>().w2b = w2b;
player.GetComponent<AIMovement>().w3b = w3b;
player.GetComponent<AIMovement>().w4b = w4b;
player.GetComponent<AIMovement>().w5b = w5b;
player.GetComponent<AIMovement>().w6b = w6b;
player.GetComponent<AIMovement>().w7b = w7b;
player.GetComponent<AIMovement>().w8b = w8b;
player.GetComponent<AIMovement>().b11 = b11;
player.GetComponent<AIMovement>().b12 = b12;
player.GetComponent<AIMovement>().b13 = b13;
player.GetComponent<AIMovement>().b14 = b14;
player.GetComponent<AIMovement>().b21 = b21;
player.GetComponent<AIMovement>().b22 = b22;
i++;
}
*/
timer = 0f;
}
}
void GetPlayerList()
{
Players.Clear();
Players.AddRange(GameObject.FindGameObjectsWithTag("Player"));
}
}
I’m trying to simulate evolution where u get eliminated if ur score is the lowest. When I use the function Destroy(List[]) from some for me unknown reason it only destroys the first and the fift element in the list. Please help me!