- Home /
Click Object to change scene
I have a script for when i click my game object (box) it changes scenes but when i click it, it just restarts my menu scene E.G game objects start from where they do but its supposed to change scenes to the actual game
SCRIPT:
 function Update () {
     if(Input.GetMouseButton(1))
         Application.LoadLevel("NewGame");
     }
Ok it worked after a bit of fiddling thanks for your help
$$anonymous$$ittyCrafting.
ok thanks for the code the scene was in build list im going to try it now. The objects do have colliders.
Answer by Kiloblargh · Jan 04, 2014 at 12:30 AM
Should be Input.GetMouseButtonDown(0) for a left click.
GetMouseButton(1) will take a right click and continue to spam Application.LoadLevel messages every frame the mouse button is held down, which could result in a crash.
Neither one detects a click on the box. You should use a collider and a Raycast to make sure that the cursor is over the button when you click, otherwise a click anywhere will load the level.
Also, you have to make sure that all your scenes are added to the project in build settings- they are not by default.
Answer by valim · Jan 04, 2014 at 02:24 PM
If you want to build that only for PC here's the code:
 private var startedLoad : boolean = false;
 function OnMouseDown(){
   if(!startedLoad){
     Application.LoadLevel("NewGame");
     startedLoad = true;
   }
 }
And as Kiloblargh said, you have to make sure that all your scenes are added to the project in build settings.
And the object you attach this script must have a collider.
The boolean is that you can't spam the LoadLevel function.
Hey, thanks for your answer, helped me a lot!
Your answer
 
 
             Follow this Question
Related Questions
Random level select 1 Answer
Application.LoadLevel strange problem 2 Answers
Load last scene/level 4 Answers
How to see what level is running? 2 Answers
Multiple Instances of My Current Scene? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                