- Home /
Bit of code repeated 4 times under different conditions, making unity "not respond"
for (int DirtPlaceY1 = 0; DirtPlaceY1 < 6; DirtPlaceY1 ++)
{
for (int DirtPlaceX1 = 3; DirtPlaceX1 < 15; DirtPlaceX1 ++)
{
GameObject CurrentCube3 = Instantiate (CubeGet, new Vector2 (HousePosition.x + DirtPlaceX1, HousePosition.y - DirtPlaceY1), Quaternion.identity) as GameObject;
CurrentCube3.GetComponent <Cube> ().Type = Cube.Types.Dirt;
CurrentCube3 = Instantiate (CubeGet, new Vector2 (HousePosition.x + DirtPlaceX1, HousePosition.y + DirtPlaceY1), Quaternion.identity) as GameObject;
CurrentCube3.GetComponent <Cube> ().Type = Cube.Types.Dirt;
}
}
for (int DirtPlaceX2 = 0; DirtPlaceX2 < 3; DirtPlaceX2 ++)
{
for (int DirtPlaceY2 = 3; DirtPlaceY2 < 12; DirtPlaceY2 ++)
{
GameObject CurrentCube3 = Instantiate (CubeGet, new Vector2 (HousePosition.x - DirtPlaceX2, HousePosition.y + DirtPlaceY2), Quaternion.identity) as GameObject;
CurrentCube3.GetComponent <Cube> ().Type = Cube.Types.Dirt;
CurrentCube3 = Instantiate (CubeGet, new Vector2 (HousePosition.x + DirtPlaceX2, HousePosition.y + DirtPlaceY2), Quaternion.identity) as GameObject;
CurrentCube3.GetComponent <Cube> ().Type = Cube.Types.Dirt;
}
}
Comment
Answer by lordlycastle · Apr 05, 2015 at 03:57 PM
Let me guess you put this in Update function? Calls to GetComponent
functions are heavy, and you are making so many calls per frame, it’s going to freeze. You making 312 calls to GetComponent
and Instantiate
each frame.
Your answer
Follow this Question
Related Questions
my rocket fires in the wrong direction 4 Answers
Changing weapons script 4 Answers
Wrong Animation Is Played 0 Answers
My object don't spawn as expected so what should I do? 0 Answers
Is there anything wrong with ragdoll wizard's default value? 1 Answer