Your problem is in your first loop. Each time you loops you are reassigning pcs with the one component from that object.
It should be something along the lines of:
foreach(GameObject go in obj) //for every object
{
pcs.Add( = GetComponent<PipeConnectorScript>()); //pcs of type script
}
You could also do this via linq:
Using System.Linq;
var pcs = objs.Where(n => n.GetComponent<PipeConnectorScript>!=null).Select(n => n.GetComponent<PipeConnectorScript>!=null).ToList();
Alternatively you can do it all in one fell swoop (since it looks like this is all in one method).
won = true;
foreach(var obj in objs)//for each script
{
var pipeScript = obj.GetComponent<PipeConnectorScript>
if (pipeScript !=null)
{
won = won && pipeScript .connected;
}
}
↧