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 On$$anonymous$$ouseUp to be called.
yes it has a collider that's why i think it weird that it doesn't work but only on unit 5
Have you an Event System in your scene ?
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 ?
Answer by Hellium · Sep 17, 2015 at 06:42 AM
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.
Answer by Darkathion · Sep 17, 2015 at 07:29 AM
using UnityEngine; using System.Collections;
public class LoadOnClick : MonoBehaviour {
public GameObject loadingImage;
public void LoadScene(int level)
{
loadingImage.SetActive(true);
Application.LoadLevel(level);
}
}
Your answer
Follow this Question
Related Questions
Hi! I am trying to use SceneManagement, but I keep getting errors. 1 Answer
Loading and Unloading scenes 2 Answers
multi scene editor 0 Answers
*JavaScript* High Score help (Need help with player prefs) 1 Answer
Please explain a switch statement? 4 Answers