Unity random generator kills programm

Hey everyone, first of all i am a complete Unity noob so please excuse any dumb questions:
I am trying to make a 3D Jump 'n Run in Unity in which you have to complete a random Stage playing as a Ball. The Stage consists of 3 lanes, each 10 Units apart, to which the Ball can Jump to.
Right now i am trying to make the randomizer which creates the Stage (The “Stage” consists of random Platforms scattered across the 3 lanes).

#pragma strict

var zPos = 7.5;
var xPos = 0;
var xHelp;
var ReMax = 15;
var Re = 0;
var Ground : GameObject;



function Start () {
    Ground = GameObject.Find("Ground");

    while (Re< ReMax){
        if (xPos == 0){
            xHelp= Random.Range(1,4);
            Debug.Log (Random.Range);
            if (xHelp== 1){
                xPos = -10;
                transform.Translate(xPos,0,0);
                Instantiate(Ground);
                transform.Translate(-xPos,0,0);
                Re += Re;
                transform.Translate(0,0,zPos);
            }
            if (xHelp== 2){
                xPos = 10;
                transform.Translate(xPos,0,0);
                Instantiate(Ground);
                transform.Translate(-xPos,0,0);
                Re+= Re;
                transform.Translate(0,0,zPos);
            }
            if (xHelp== 3){
                xPos = 0;
                transform.Translate(xPos,0,0);
                Instantiate(Ground);
                transform.Translate(-xPos,0,0);
                Re += Re;
                transform.Translate(0,0,zPos);
            }
            
        }

    }

}

Unity itself doesnt give me an Errormessage when i try to run the Script but the program just frezzes as soon as i hit play. The Gameobject “Ground” are the Platforms the program is supposed to create. I have never worked with Instantiate so i kinda suspect my error to be the spawning of the Platforms.
I’ve been stuck here for a while and dont realy know how to go on, so if someone would have a suggestion, i’d be very grateful.

You have an infinite loop in your Start function, which is why your game is freezing. Your loop is infinite because Random.Range(1,3) will only ever return the integers 1 or 2. When you use Random.Range() with integers, the range of possibilities start from the first number and exclude the last number. The way your loop is set up, it will never end.

Can confirm, infinite loop. This issue can happen when you least expect, may be good practice to stick in a max number of iteration cycles. May help to prevent the editor from locking up. Or Unity could provide a quick stop feature in case this situation happens, that doesn’t involve restarting the editor.

The loop is going to keep executing until the condition evaluates to false. Your condition is:

Re < ReMax

Re is 0, therefore doing Re += Re gives you zero, as 0 + 0 = 0. Therefore, Re is never increasing, as a consequence it will never be larger than ReMax, hence the infinite loop. If you are setting Re in the editor then make sure that it isn’t 0, or less than 0.

One other thing worth mentioning, if xPos is not 0, then Re is never increased. If Re is never increased then it will never exit the loop. Why not change over to a for loop? May be safer, and you can specify a maximum number of tiles to place. Same principle, you’ll just be iterating until you’ve placed the maximum number of tiles, rather than managing the counter manually in a while loop.

for(int iteration = 0; iteration < maxNumberTiles; iteration++)
{
       //Place your tiles
}

That should remove the editor freezing issue.

Hopefully this helps.