I’m making a choice based game where each “Decision Panel” has a bool that is ticked when a valid decision is made. What I want is a way for my “EventManager” to detect when all those bools are ticked.
I’d use a standard getcomponent for each “Decision Panel” but not every scene will have the same number of decisions to be made, so I feel like an array would be more tidy, but arrays really do my head in. (I can never seem to get them to work correctly and when I try a for loop is always comes up with OutOfRange)
// Start is called before the first frame update
void Start()
{
canvas = GameObject.FindGameObjectWithTag("MainCanvas");
}
// Update is called once per frame
void Update()
{
gold = canvas.GetComponent<StatManager>().Gold;
soldiers = canvas.GetComponent<StatManager>().Soldiers;
citizens = canvas.GetComponent<StatManager>().Citizens;
food = canvas.GetComponent<StatManager>().Food;
farms = canvas.GetComponent<StatManager>().Farms;
lumber = canvas.GetComponent<StatManager>().Lumber;
if(decision1 == null)
{
costGold1 = 0;
costSoldiers1 = 0;
costFood1 = 0;
costFarms1 = 0;
costCitizens1 = 0;
costLumber1 = 0;
}
else
{
costGold1 = decision1.GetComponent<CostInformation>().costGold;
costSoldiers1 = decision1.GetComponent<CostInformation>().costSoldiers;
costFood1 = decision1.GetComponent<CostInformation>().costFood;
costFarms1 = decision1.GetComponent<CostInformation>().costFarms;
costCitizens1 = decision1.GetComponent<CostInformation>().costCitizens;
costLumber1 = decision1.GetComponent<CostInformation>().costLumber;
}
if (decision2 == null)
{
costGold2 = 0;
costSoldiers2 = 0;
costFood2 = 0;
costFarms2 = 0;
costCitizens2 = 0;
costLumber2 = 0;
}
else
{
costGold2 = decision2.GetComponent<CostInformation>().costGold;
costSoldiers2 = decision2.GetComponent<CostInformation>().costSoldiers;
costFood2 = decision2.GetComponent<CostInformation>().costFood;
costFarms2 = decision2.GetComponent<CostInformation>().costFarms;
costCitizens2 = decision2.GetComponent<CostInformation>().costCitizens;
costLumber2 = decision2.GetComponent<CostInformation>().costLumber;
}
public void Option1()
{
if (costGold1 <= gold && costSoldiers1 <= soldiers && costCitizens1 <= citizens && costFood1 <= food && costFarms1 <= farms && costLumber1 <= lumber)
{
decisionINT = 0;
DecisionMade = true;
Checkmark[0].text = "X";
Checkmark[1].text = "";
Checkmark[2].text = "";
Checkmark[3].text = "";
}
}
as you can see, it’s very very repetitive (I’ve cut a lot out, but I’ve iterated it 4 times and limited each decision to a max of 4 options, because I couldn’t get an option array working.) but my Event Manager script is blank, and I don’t want it to end up looking like this.
My hope is that if I can learn a little bit about correctly manipulating arrays with this Collecting all the Bools of an array of objects I can use that knowledge to make this script look neater.