C# Stuck on creating my Turn based battle system
Currently I am trying to create a RPG turn based battle system. There is going to be multiple heroes and enemies in each battle. The turn order is based off of their speed stat. Currently I have them all assembled and placed into a List that sorts them by speed. (Highest to lowest).
The part that I am stuck at is how do I tell the character what place it is in the list index? ex. The fastest character is going to go first, 2nd fastest character is going to go second, so on and so forth.
This is the code so far:
public List allCharacters = new List();
// Use this for initialization
void Start () {
FindCharacters();
TurnTable();
}
// Update is called once per frame
void Update () {
}
void FindCharacters() {
GameObject[] characters = GameObject.FindGameObjectsWithTag("Character");
foreach (GameObject character in characters){
allCharacters.Add(character);
}
}
public void TurnTable () {
allCharacters = allCharacters.OrderBy(x => x.GetComponent<Stats>().speed).ToList();
}
Any help would be greatly appreciated.
Think I might've found the answer.
Added a public int turnCount;
With this I was able to turn the turnCount into a current turn indicator of sorts. Like so:
turnCount = allCharacters.Count - 1;
allCharacters[turnCount].GetComponent<HeroState$$anonymous$$achine>().isTurn = true;
Since we are working with Lists element 0 is a thing so its important to $$anonymous$$us 1 from the turnCount so that we don't over shoot the list count. As of now this seems to be working for me. I'll post this in case anyone else is looking for the solution.