I'm trying to have objects become visible only when they fall within a particular area, however I'm having some trouble with GetComponent.
foreach( Plank plank in planks )
{
plank.CreateGameObjects();
plank.plankObject.transform.SetParent(world.transform);
if (plank.plankObject.transform.position.z < ymax)
if(plank.plankObject.transform.position.z > ymin)
if(plank.plankObject.transform.position.x > xmin)
if(plank.plankObject.transform.position.x < xmax)
plank.plankObject.GetComponent().enabled = true;
else
plank.plankObject.GetComponent().enabled = false;
}
I've checked the conditions and there doesn't seem to be a problem there (i.e. I had debug log print a message to the console when an object met the selection criteria and that went fine), but when I add in the lines to do with GetComponent I run into some problems. There are objects that do or don't have a mesh, and the ones that do/don't are consistent between runs, however whether or not an object has a mesh seems to be completely unrelated to the conditions I've set out.
Is this a common (relatively) problem with GetComponent, or am I just missing something obviously wrong?
↧