As far as I understand you want to select first avaliable character of some array through static script that will save the picked unit. If that's the case, you can try the following script:
Script on the unit:
Script on the unit:
public class UnitScript
{
[SerializeField] private bool avaliable;available; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
public void SetAvaliableSetAvailable(bool state)
{ avaliableavailable = state; }
public bool GetAvaliableGetAvailable()
{ return avaliable;available; }
}
Your Code:
Your Code:
public static class CharacterChange
{
public static GameObject PickedUnit;
public static void SelectUnit(GameObject[] units) // call this function with array input
{
foreach(GameObject unit in units)
{
if (unit.GetComponent<UnitCode>().GetAvaliableGetAvailable() == true)
{
// you can make local variable and save the progress here, for example
// PickedUnit = unit;
// return; // return the wanted unit
}
}
}
}
AttackAttach the UnitScript to the units you wanna select/interact with.