Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Multiple Scene Switching on one script!

Discussion in 'Scripting' started by SP-Designs, Nov 8, 2015.

  1. SP-Designs

    SP-Designs

    Joined:
    Oct 13, 2015
    Posts:
    184
    Hi there! Me and my friend have made a dot game so when the red one is clicked the game loads lvl : Main Menu and when a blue dot is clicked it loads the next level.So far i got 2 levels so everything works fine but how do i add on the same object another script so when it is clicked it loads the next lvl?Because here is my code :
    Code (csharp):
    1.  
    2. void OnMouseDown()
    3.    {
    4.      Application.LoadLevel("Level 2");
    5.    }
    .

    But i want the blue dot to load level 3 for example when it's clicked in level 2 and so on.How do i do that?Please help me thanks!
     
  2. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    You could try using something like:
    Let me know if this works as im not certain.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LoadNextLevel : MonoBehaviour
    5. {
    6.     public int CurrentlyLoadedLevel;
    7.  
    8.     void Awake()
    9.     {
    10.         CurrentlyLoadedLevel = Application.loadedlevel;
    11.     }
    12.  
    13.     void OnMouseDown()
    14.     {
    15.         Application.LoadLevel (CurrentlyLoadedLevel + 1);
    16.     }
    17. }
     
  3. SP-Designs

    SP-Designs

    Joined:
    Oct 13, 2015
    Posts:
    184
    I get an error saying that unity.application does not contain a definition for loaded level!
     
  4. UbiquitousStudio

    UbiquitousStudio

    Joined:
    Oct 11, 2015
    Posts:
    24
    If it's all 2d stuff just add some buttons to them. Then add the button functions like this

    Code (CSharp):
    1. public void StartLevel1()
    2. {
    3.    Application.LoadLevel("LevelName")
    4. }
    5.  
    6. public void StartLevel2()
    7. {
    8.    Application.LoadLevel("LevelName")
    9. }
    10.  
    11. public void StartLevel3()
    12. {
    13.    Application.LoadLevel("LevelName")
    14. }
    Then put it on a empty gameobject on every scene, link the buttons up. However don't use this in a actual game cause it's really easy to hack and people would just skip through the game. That's where button listeners come in pretty good.
     
  5. SP-Designs

    SP-Designs

    Joined:
    Oct 13, 2015
    Posts:
    184
    isn't there something safer? Because i don't know anything about buttons but i will try to work it out!
     
  6. UbiquitousStudio

    UbiquitousStudio

    Joined:
    Oct 11, 2015
    Posts:
    24
    Yes using gameobject.find and make variables private. If you only run it at start and once with few buttons you won't even notice it.