- Home /
How Do I Link Different Scenes?
I have a game where you roll a ball around and collect a certain amount of objects while trying to avoid obstacles and not fall off the given map. How do I link another level, so that when the player finishes the first round, they can automatically be taken to the next one, or get a choice to move to the next one? The more answers the better! Thanks in advance!
Answer by Praydude · Nov 11, 2016 at 08:34 AM
There is a fantastic Tutorial on this in the Live training sessions. Here is the link... https://unity3d.com/learn/tutorials/topics/user-interface-ui/creating-main-menu
Super awesome and easy to follow. Good luck!
Answer by tanoshimi · Oct 30, 2016 at 09:33 PM
File -> New Scene?
How would I link the scene, though? So like when you click "Play" on the First Scene which is $$anonymous$$ain $$anonymous$$enu, how do I make it so that it directs the person to the game scene (which I have made.) Would I need a script? If so, what should I put?
Are you talking about a LOADING SCENE? Do you want to change scenes? Example:
There is a main menu with a "Start Game" button. When you click the button, you go to other scene. Are you trying to do this? I can help you with that =]
Yes, that's exactly what I'm trying to do. Like when you first load the game, the main menu pops up. You click "Start" and it takes you to another scene.
Answer by josetgg · Nov 01, 2016 at 11:49 PM
You need to add the scenes to "scenes in build" on the build settings window. Then on a script that lives on a gameobject in your scene yo have to call UnityEngine.SceneManagment.SceneManager.LoadScene("YourSceneName"); when you want the scene to change. You can avoid the long line by adding using UnityEngine.SceneManagement; to the top of your script outside of the class and just use SceneManager.LoadScene("YourSceneName");.
Answer by Zitoox · Nov 02, 2016 at 12:50 AM
I assume that you already made your scene and that you just need the script. If not, just reply and i will try to help. It should work!
First, create a Javascript and poste the following code:
var isQuitButton = false;
function OnMouseUp() {
//Mark this checkbox if it is a Quit Button.
if (isQuitButton) {
//If the checkbox is marked, the game will close.
Application.Quit();
}
else {
//The level to load. Insert the number here.
Application.LoadLevel(2);
}
}
Attach this to your button/collider/text/etc... Note that you will need to make one script for each scene, as it is difficult to make one script for all the scenes in your game. After attaching the script to your button, you will see a checkbox saying "Is quit button". If you have an exit button in your game, attach the script to it and mark the box. If it isn't a quit button, just ignore. It is pretty simple, when you click the button, the game will load your scene.
As you might now, in the BUILD settings, you can attach the scenes of your game. Each scene has a number. For an example, if i want to load my tutorial scene, i will check in the build which number it has. If it has the number "2", then i am going to use 2 in this part of the code: Application.LoadLevel(2);
Hope it helped!
Oh, the scene might become dark and gray when you load it inside the editor, but relax, it is just in the editor. If you build your game, it will work normally. Unfortunatelly, i can't guide you on here, because i know some loading tricks that might be very helpfull. I wish i could =\