button that change scene on click
Hi im a noob at scripting and i need a script or something that make that when we click on a button it change the scene i tried a lot of script that i found on the forum but none of them work for me so i someone could help me i will be grateful PS : Sorry for my bad english it's not my native language
I'm a noob too, so I have this question toooooo.
Answer by nordaj123 · Dec 31, 2016 at 01:41 AM
do something like this:
using UnityEngine.SceneManager;
...
void OnMouseUp()
{
SceneManager.LoadScene("SceneName", LoadSceneMode.single);
}
You will also want to go into build settings and add all scenes into the list. Then you will need to add a 2d collider to your button. This is only the loading scene parts but you can do other things like changing the button size OnMouseDown.
Answer by mafanbong8819 · Jan 30, 2017 at 06:37 AM
Here is a video tutorial to change scene using button, i think is clear cause most of the step is zoom, so you can read it easily.
video-change scene using button
add this script to the main camera
create a button
from the inspector of UIbutton, over the onclick() function, add camera as object, then choose function call menuscript, then select change scene function.
open new scene
add scene to the platform
done.
using Unityengine; using System.Collections;
public class MenuScript : MonoBehaviour { public void ChangeScene(string sceneName) { Application.LoadLevel(scenceName); } }
Answer by SamTam · Jan 16, 2017 at 10:07 AM
On you're script just add:
public void OnMouseClick(){ Application.LoadLevel("Here put the name of the scene"); }
Then select the button and scroll down until you find Button script. At the bottom of the component there should be a "On click ()".
Then put the script bellow the "On click()" then next to it there it should say No Function. Click on that and find you're script's name and select OnMouseClick() option.
Answer by OwlTeaGames · Sep 30, 2017 at 06:51 PM
Here is a video I made of How To Change Scenes with the latest unity build, 2017. It's part of a VR series but should work just fine for any project! https://youtu.be/MeWjyLpsYw8!
Just remove the exclamation point, then the link works. @J$$anonymous$$cGregor
Answer by Huzaifa220 · Sep 26, 2019 at 05:45 AM
using UnityEngine.UI;
public string sceneName; public Button loadSceneBtn;
void Start(){ loadSceneBtn.onClick.Addlistner(ChangeScene); }
void ChangeScene(){ SceneManager.LoadSceneAsync(sceneName); }