- Home /
On object click change scene
My script to change level by clicking on a game Object is not working please help! it has an error:BCE0044: Expecting } found ". it's in JavaScript.
SCRIPT:
function Update () {
if(Input.GetMouseButton(0))
Application.LoadLevel("NewGame");
Thanks
Answer by YoungDeveloper · Dec 24, 2013 at 01:00 AM
You forgot a bracket - close Update method.
function Update () {
if(Input.GetMouseButton(0))
Application.LoadLevel("NewGame");
}
Hi @YoungDevelopper! i have the same problem of JTS2111. how do I change the scene just by clicking an object?
Hi @Gianluca90 code above simply loads certain named scene when mouse button is pressed. Clicking on specific objects and do actions is out of this question scope. But in short, if its UI use expected event listeners, if it's a world object - use raycasting.
I am trying to put multi cubes in a scene so when clicked it will take me to different scenes will this work for that??
@EDZVR please don't post a question/comment as a new answer.
And yes, it should work. Try it and see!
Answer by N1warhead · Apr 20, 2016 at 07:11 PM
Do not use Application.LoadLevel, it is now depreciated. So I would assume it's done that way for good reason.
Use SceneManager now.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement; // <<<<<< ADD THIS.
public class Example : MonoBehaviour {
// Use this for initialization
void Start () {
SceneManager.LoadScene ("NameOfScene"); // <<<< Then Do this.
SceneManager.LoadScene (0); // OR THIS (int = scene id in build menu)
}
EDIT: And to change a scene by clicking Object, such as UI Button.
public void WhatEver(){ Same code as above with loading scenes, then drag and drop this script onto the button and feed it into the button OnClick at the bottom. }
Hello, I'm new to unity and I'm trying to use the Scene$$anonymous$$anager to change the scene when I click on a certain GameObject but i can't manage to do it. Could you tell me how would you write the code for this? Thanks!