Skip to main content
3 of 6
deleted 2 characters in body

As far as I understand you want to select first avaliable character of some array. If that's the case, either attack the script on the unit and check if it's avaliable:

Script on the unit:
public class UnitScript
{
   [SerializeField] private bool avaliable; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
   public void SetAvaliable(bool state)
   { avaliable = state; }

   public bool GetAvaliable()
   { return avaliable; }

}


Your Code:

public class CharacterChange
{
   [SerializeField] GameObject[] units; // put all the object's that you want to interact with (with the UnitScript) here

   public void SelectUnit()
   {
     foreach(GameObject unit in units)
     { if(unit.GetComponent<UnitCode>().GetAvaliable() == true)
     { 
       // code to select this unit
     return;
     }
   }
}

or just make array of booleans and go through each through for loop and choose the unit with the same [i], but that's not so suggested way.