For and Foreach not getting all child transform
I'm making a simple tetris game using the concept from here https://noobtuts.com/unity/2d-tetris-game/ with my own modification.
Basically I'm making a gamemanager script and putting it in an empty gameobject instead of applying it into individual pieces since I think that would be easier for me.
I'm using a class to check if the position of the tetromino prefab's child (each individual block) is in a valid position and it looks like this:
bool validPos(GameObject obj)
{
for(int x = 0; x < 4; x++)
{
Transform child = obj.transform.GetChild(x);
Debug.Log("Child pos:"+child.position.x+", "+child.position.y+" - Child : "+child.ToString());
Debug.Log("child: "+child.ToString());
if(child.position.x < 5 && child.position.x >-5 &&
child.position.y > -11)
{
return true;
}
}
return false;
}
The problem is, somehow in the runtime, the for loop will only check the first child even tho there's 4 child in a prefab, even if I use the debug log to show how many child it has, it shows there's 4. It's the same when I use foreach. Add comment
Your answer
Follow this Question
Related Questions
Looking through all the children doesn't work 1 Answer
Animation transition problem 1 Answer
Car Controls without physics. 1 Answer
Make object move back and forth 2 Answers
Vector3.Lerp not working properly, making the player bounce around 2 Answers