Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

ok so im following this tutorial about prims maze and everything is correctly coded I followed everything in pretty much the exact same way. the problem is that when i hit the play button unity freezes up and the grid doesn't form. its fine when its just instantiating the x for(int x=0,x

this is the code i used

this is the tutorial i am following

public class GridScript : MonoBehaviour { public Transform CellPrefab; public Vector3 Size;

void start()
{
    CreateGrid ();
}

void CreateGrid(){
    for(int x = 0; x < Size.x;x++){
        for(int z = 0; x < Size.z; z++){
            Instantiate(CellPrefab, new Vector3(x, 0, 0), Quaternion.identity);
        }
    }
}

}

but when I have used this code for a different grid it works perfectly fine public Transform PlatPrefab; public Vector3 Size; public int platX, platY, playZ;

// Use this for initialization void Start () { MakeGrid(); }

// Update is called once per frame void MakeGrid(){

    for (int x = 0; x < Size.x; x++) {
            for (int z = 0; z< Size.z; z++) {

            Instantiate(PlatPrefab, new Vector3(x+platX,platY,z+playZ), Quaternion.identity);
    }
}

}

Unity Grid System

does any one know why this is happening

share|improve this question

put on hold as off-topic by bummzack, Anko, Byte56 yesterday

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – bummzack, Byte56
If this question can be reworded to fit the rules in the help center, please edit the question.

3  
This is a "debug my code" question and considered off-topic here. You have a problem in your nested for loop.. the second one should compare z < Size.z and not x < Size.z as you're currently doing. This results in an endless loop -> Unity freezes. –  bummzack yesterday
    
Learn to use the debugger before you go any further. It's invaluable at finding errors like this and helping you better understand how the code works. –  Byte56 yesterday
    
I have had this problem a few times, but have managed to solve the problem just by double-checking my code. Learning to use the debugger is important, as is learning to debug in general. –  iRperson yesterday
    
your right i completely missed that even though i did double check my code...then again it was around midnight when i was doing this @bummzack –  john smith yesterday

Browse other questions tagged or ask your own question.