Hello, obviously I have a problem as I am asking a question.
So here is my problem,
I have multiple game objects, named block. They all have the same script attached to them.
In this script a boolean is set to true when these said blocks connect to each other. This boolean works as i have tested it out thoroughly.
I have another, controller object say, it’s purpose is to end the game when all these blocks are connected ie, when all the booleans are true.
I have been trying to figure it out now for hours and i can’t seem to find anything.
So here is some of my code:
This is attached to the controller.
obj is the gameobjects that the script with the boolean are attached to.
foreach(GameObject go in obj) //for every object
{
pcs = go.GetComponents(); //pcs of type script
}
foreach(PipeConnectorScript sc in pcs)//for each script
{
if(sc.connected == true)//if the boolean is true then win
{
won = true;
}
else
{
won = false;
}
}
if(won == true)
{
Debug.Log("Winning!");
}
Now what happens is only if some are connected then it still equals true and the log is passed. What I require is that aaallllll the booleans from each object are set to true before winning the game.
AFTER FURTHER INSPECTION
the line
pcs = go.GetComponents();
only returns one component for some reason as i have checked in the inspector.
so this could be the problem. Although i do not see why as pcs is an array declared at the top like so.
PipeConnectorScript pcs;
I hope i have asked my question in as much detail as possible.
If not then i will elaborate further,
thanks much appreciated.
even though this may help with the code. i have tried it out and i still get the same result, the game is won even though not all are connected.
– Samir_1