In your Start, you should get all of the GameObjects that matter. You could tag them all with some specific tag like "Party" or something, then use *GameObject.FindGameObjectsWithTag("Party")* which returns an array of GameObjects. Then, you would loop through that array and call *GetComponent()* on each object and assign that to an array stored as a field.
public class TurnBasedStates : MonoBehaviour
{
private CharacterStats[] m_CharacterStats;
private void Start()
{
GameObject[] partyMembers = GameObject.FindGameObjectsWithTag("Party");
m_CharacterStats = new CharacterStats[partyMembers.Length];
for (int i = 0; i < partyMembers.Length; i++)
{
m_CharacterStats[i] = partyMembers[i].GetComponent();
}
}
private void Update()
{
switch (currentState)
{
case BattleStates.NEXT:
{
for (int i = 0; i < m_CharacterStats.Length; i++)
{
//if (m_CharacterStats[i].initiative meets whatever criteria)
// take some action
}
}
break;
}
}
}
[GameObject.Find][1]
[GameObject.FindGameObjectsWithTag][2]
[1]: http://docs.unity3d.com/ScriptReference/GameObject.Find.html
[2]: http://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html
↧