Hello,
I’ve tried around with Arrays and Lists for a while and got one working. I finally managed to make a list which orders the values of every single GameObject from high to low value. The problem now is that when I click on next turn. He doesn’t add +1 on the list number. The log keeps on updating with 0, 1, 2, 3, 0, 1, 2… etc. It does switch the player but to the number 2 in the list (so actually gameobject 3). How do I fix this? Here is the code:
public class TurnBasedStates : MonoBehaviour {
private CharacterStats statsmanager;
public List<GameObject> characterList = new List<GameObject>();
private GameObject currentCharacter;
public enum BattleStates{
START,
ACTIONPHASE,
ANIMATION,
ENDTURN,
LOSE,
WIN,
NEXT
}
private BattleStates currentState;
// Use this for initialization
void Start () {
GameObject[] allCharacters = GameObject.FindGameObjectsWithTag ("Character");
allCharacters = GameObject.FindGameObjectsWithTag("Character").OrderBy(go => go.GetComponent<CharacterStats>().initiative).ToArray();
System.Array.Reverse (allCharacters);
foreach (GameObject character in allCharacters)
{
characterList.Add (character);
}
}
// Update is called once per frame
void Update () {
//Debug.Log (currentState);
switch (currentState) {
case(BattleStates.START):
currentCharacter = characterList[0];
currentCharacter.GetComponent<CharacterStats>().isActive = true;
break;
case(BattleStates.ACTIONPHASE):
break;
case(BattleStates.ANIMATION):
break;
case(BattleStates.ENDTURN):
break;
case(BattleStates.LOSE):
break;
case(BattleStates.WIN):
break;
case(BattleStates.NEXT):
currentCharacter.GetComponent<CharacterStats>().isActive = false;
for (int i = 0; i < characterList.Count; ++i)
{
currentCharacter = characterList*;*
-
currentCharacter.GetComponent<CharacterStats>().isActive = true;*
-
Debug.Log(i);*
-
currentState = BattleStates.ACTIONPHASE;*
-
}*
-
//statsmanager = GameObject.Find("Character").GetComponent<CharacterStats>().initiative;*
-
//currentState = BattleStates.ACTIONPHASE;*
-
break;*
-
}*
-
}*
-
void OnGUI(){*
-
if(GUILayout.Button("END TURN")){*
-
currentState = BattleStates.NEXT;*
-
}*
-
}*
}