Search Unity

Trying to swap scene when clicking a button

Discussion in 'Scripting' started by Hotpots, Sep 3, 2015.

  1. Hotpots

    Hotpots

    Joined:
    Apr 9, 2015
    Posts:
    143
    Hey guys,
    I just simply want to swap scene when I click a button, atm I'm using the following script when attached to the button, however it's doing nothing.

    using UnityEngine;
    using System.Collections;

    public class PlayGameButton : MonoBehaviour {
    void OnMouseDown() {
    Application.LoadLevel("Scene2");
    }
    }​
     
  2. Hotpots

    Hotpots

    Joined:
    Apr 9, 2015
    Posts:
    143
    I've tried this too and it doesn't work :(

    using UnityEngine;
    using System.Collections;

    public class PlayGameButton : MonoBehaviour {
    if(Input.GetMouseButtonDown(0)){
    Application.LoadLevel("Scene2");
    }
    }
     
  3. Custardcs

    Custardcs

    Joined:
    Aug 26, 2015
    Posts:
    57
    Hey bud i found this to be usefull..



    also remember you have to add your two scenes to (build settings)
     
  4. Hotpots

    Hotpots

    Joined:
    Apr 9, 2015
    Posts:
    143
    Hey,
    Firstly I appreciate the help Custard and it worked perfectly however it's not exactly what I wanted
    I don't want to draw my own button using Unity's old GUI, I don't want a boring old box to click, as you can see from the screenshot I have made my own buttons "Play Game" and "Instructions" by using GameObject > UI > Button in the menu.
    Is there a way I can attach some sort of script to a button in order for it to change scene?
    Like anything similar to what I attempted?

    Screenshot of Main Menu - http://i.imgur.com/prdbcKT.png


    Edit: Do I use Button.onClick somehow?
     
  5. Hotpots

    Hotpots

    Joined:
    Apr 9, 2015
    Posts:
    143