Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by vincentamato · Dec 16, 2014 at 01:49 AM · uibuttonscene-change

Changing Scene When Button Tapped

Hi. I created a button by going to create > ui > button. How would I change the scene if the button is clicked or tapped? I know it isn't OnGUI(), right? Please help. Thanks!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image z25assassins · May 27, 2016 at 07:08 PM 0
Share

if your using unity 5

https://www.youtube.com/watch?v=TEq4P0kDAtE&feature=youtu.be

7 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by podmaster · Dec 16, 2014 at 01:56 AM

You can do:

 Application.LoadLevel (Destination);
 
 //FOR EXAMPLE
 Application.LoadLevel ("PlayScene2");


Remember, in order for this to work you must open the file > build setting and drag and drop the scenes you are gonna use into the build settings.

REF: http://docs.unity3d.com/ScriptReference/Application.LoadLevel.html

//EDIT// BTW what i do is create this simple script:

 //LOAD LEVEL SCRIPT
 #pragma strict
 
 var Destination : String;
 
 function LoadScene () {
     Application.LoadLevel (Destination);
 }


Attach it to the button that loads levels and on the inspecter type in the desire scene destination, then add an event to the button component and use the button it self to execute the LoadScene() function.

Here is another answer about this topic: http://answers.unity3d.com/questions/777818/46-ui-calling-function-on-button-click-via-script.html

//EDIT//

HOW TO DO IT

1.select you button, on the inspector you must have a "button" component if not add it.

2.Then drag and drop the object with the loadlevel script

3.Select the script > function() and when the button gets clicked or taped the selected function will be executed.

http://answers.unity3d.com/storage/temp/37098-untitled-1.jpg alt text

I recommend you to watch this video shows everything you need to know (Almost) https://www.youtube.com/watch?v=EOX6itCuKOc


untitled-1.jpg (180.1 kB)
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vincentamato · Dec 16, 2014 at 01:57 AM 0
Share

@podmaster Yes I know about Application.LoadLevel, but how would I detect a click or tap?

avatar image Joppix · Oct 09, 2015 at 08:31 PM 0
Share

Hi, i hope you will see this comment :). I don't want to open another topic for this, so i ask you here. I have the same problem with the last version of unity, how can i do? Application:Loadlevel Needs to be under Void.Update? Please, Help me, i really need it!

avatar image podmaster Joppix · Oct 09, 2015 at 09:04 PM 0
Share

Check the documentation http://docs.unity3d.com/ScriptReference/Application.LoadLevel.html

No need to call the Application class inside update. Remember to make this work you have to add the scene to the build settings.

Just call Application.LoadLevel("SCENE_NA$$anonymous$$E") from your class. try it on Start() for a fast test

avatar image NuclearKitCat · Jun 28, 2017 at 11:28 AM 0
Share

thx this was very very helpful ;)

avatar image gusfanpoon · Jul 02, 2017 at 08:38 AM 0
Share

in the button i already put the button , but in no function i already click but just have a "String Name" the code is same with ur , please help me im urgent

avatar image FireGuardianFilms · Aug 01, 2017 at 01:53 PM 0
Share

thx i rlly, need this script and setup, keep it up :D

avatar image
1

Answer by Stealthygolem · Dec 16, 2014 at 02:38 AM

For your button, there is a place that says "OnClick()" And then some extra stuff here.

If you want to load a scene, when a button is pressed. You first need to have a script up with a function to load a scene, and this script must be attached to an object you refer to. I use my script on the entire "Canvas" parent!

In this script. Create this method, and it has to be public!

 public void LoadStage()  {
     Application.LoadLevel ("YourLevel");
 }



In the image I attached, you can see how it looks like for the button! So, whenever this button is clicked (OnClick()), it will see that I reference a script on a gameObject, and a specific method as well! This will exute the method when pressed. alt text


helperman.png (18.1 kB)
helperman.png (40.3 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mnmwert · Jun 14, 2016 at 08:36 PM 0
Share

Thank you it works!

avatar image gusfanpoon · Jul 02, 2017 at 08:38 AM 0
Share

in the button i already put the button , but in no function i already click but just have a "String Name" the code is same with ur , please help me im urgent

avatar image
0

Answer by aditya007 · Dec 16, 2014 at 02:56 AM

Do like this (Inside OnGUI() function)

     if(GUI.Button (start, "Start Game"))
     {
         Application.LoadLevel("SceneName");
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by FFVDGames · Dec 10, 2015 at 05:14 PM

I do this: if (Input.GetMouseButtonUp(0)) { Application.LoadLevel ("Scene name here"); }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by rohitjathot · Jun 22, 2017 at 11:04 AM

//first do this

using UnityEngine.SceneManagement;

//then use this code

SceneManager.LoadScene(index);

//OR

Application.LoadLevel (index);

//index is index of your scene

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

41 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

On off game objects 1 Answer

how to run Sprint 1 Answer

New UI Button Dynamic onClick Listener problem 1 Answer

Fading Out UI On Play 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges