x


Application.LoadLevel works only sometimes

I created a start with some pictures on it and a slider where the player can adjust the difficulty of the game. After that I use Application.LoadLevel to start the game. There are two strange things happening, when I klick on the start button:

  • The slider switches to the center automatically
  • The new scene is only loades after the second click on the button.

Here is the code:

function OnGUI ()
{
 screenW = Screen.width;
 screenH = Screen.height;
 var positionRect = Rect(screenW*0.5-screenW*0.25-easy.width*screenH*0.1/easy.height, screenH*0.5,easy.width*screenH*0.2/easy.height,screenH*0.2);
 //GUI.Box (Rect(0,0,screenW,screenH),""); //block other interactions with a full screen box
 GUI.DrawTexture(Rect(20,20,screenW-40,titleScreen.height*(screenW-40)/titleScreen.width),titleScreen, ScaleMode.StretchToFill,true,0);

 GUI.DrawTexture(positionRect,easy, ScaleMode.StretchToFill,true,0);
 positionRect.center.x = screenW*0.5;
 positionRect.width =middle.width*screenH*0.2/middle.height;
 GUI.DrawTexture(positionRect,middle, ScaleMode.StretchToFill,true,0);
 positionRect.center.x = screenW*0.75;
 positionRect.width =hard.width*screenH*0.2/hard.height;
 GUI.DrawTexture(positionRect,hard, ScaleMode.StretchToFill,true,0);
    difficulty = GUI.HorizontalSlider (Rect (screenW*0.5-screenW*0.25, screenH*0.7, screenW*0.5, screenW*0.125), difficulty, 50.0, 5.0);
    if (GUI.Button(Rect(screenW*0.5-screenH*0.1,screenH*0.8,screenH*0.2,screenH*0.2),startIcon))
    {
     Application.LoadLevel("MainScene");
    }
    //GameObject.Find("MainControllerObject").GetComponent.<MathScript>().difficulty = difficulty;

}

Any ideas?

more ▼

asked Aug 08 '12 at 07:16 AM

fschaar gravatar image

fschaar
40 6 9 16

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3447
x263
x242

asked: Aug 08 '12 at 07:16 AM

Seen: 247 times

Last Updated: Aug 08 '12 at 07:16 AM