Search Unity

How to switch between scenes?

Discussion in 'Scripting' started by OkeyNik, Jan 26, 2018.

  1. OkeyNik

    OkeyNik

    Joined:
    Mar 14, 2017
    Posts:
    41
    I have Unity 2017.2.0. In old versions This works

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class ButtonManager : MonoBehaviour {

    public void econombut (string newGameLevel)
    {
    SceneManager.LoadScene (newGameLevel);
    }
    }

    And this is also not working

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class ButtonManager2 : MonoBehaviour {

    public void econombut ()
    {
    SceneManager.LoadScene (1);
    }
    }


    But now non of this codes are working and I dont know how to switch scene. I want to click a button called "econombut" and then go to Scene "1". But now in "On clock" is no functions like before. P.S. I allready add scenes in build settings, but is still doent work like before.

    Also i look a lot of videos in YouTube and they doesnt help because they use old codes. Please help me
     
  2. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Please use code tags, as described in the stickied post at the top of every forum here.

    In order to call a function from a Button, that function has to be referenced in the OnClick event in the inspector. Watch this video on the Unity Learn site for more information, or check the manual for UI.Button, or check the scripting documentation if you want to see what you can access in code.
     
    Last edited: Jan 26, 2018