how to make a script that goes to the next scene if you click a gameobject in unity 5

in the old unity i learned from a tutorial how to make a script to do that but now in unit 5 it doesn’t work. can someone help me with changing the code so that it works. on this link is the tutorial youtube link

and this is the code line in java

hope someone can help me

greetings danny

var levelToLoad : int;
var soundhover : AudioClip;
var beep : AudioClip;
var QuitButton=false;
function OnMouseEnter(){
GetComponent.<AudioSource>().PlayOneShot(soundhover);
}
function OnMouseUp(){
GetComponent.<AudioSource>().PlayOneShot(beep);
yield new WaitForSeconds(0.35);
if(QuitButton){
Application.Quit();
}
else{
Application.LoadLevel(levelToLoad);
}
}
@script RequireComponent(AudioSource)

Are you sure there is a collider on the object ? It's necessary if you want OnMouseUp to be called.

i did and the only thing that change is the shadow on the object that's clickt . maybe you can try to make a scene yourself if you have time ?

2 Answers

2

I made an empty scene to test, here are the indications :

  • Make sure the scene is in the Build Settings
  • Make sure there is a collider to the object. The object musn’t Ignore Raycast layer
  • Add the script you’ve created, but don’t forget that Application.Quit can be called in a build only. Take a look here for the workaround in the editor.

using UnityEngine;
using System.Collections;

public class LoadOnClick : MonoBehaviour {

public GameObject loadingImage;

public void LoadScene(int level)
{
	loadingImage.SetActive(true);
	Application.LoadLevel(level);
}

}

The reason I did that is because my player is rolling. If I just attached the camera to it the camera would spin with the player.