Author Topic: Load new Scene on Button Press  (Read 2925 times)


  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Load new Scene on Button Press
« on: January 22, 2018, 02:52:19 AM »
Hi, i am new to ngui. I want jump to the next Scene on Button Press. It works, but it is not very flexible.

public void OnClick ()
SceneManager.LoadScene (1);

How can i have a public int that i can change on the Button it self? The public int is not shown in Inspector like in Unitys Ui system.
I want to have something like this or a better way to organize things. Any ideas? Thanks for your time

   public int changeScene;

      // Use this for initialization
      public void OnClick (){
         SceneManager.LoadScene (changeScene);

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Load new Scene on Button Press
« Reply #1 on: January 31, 2018, 06:24:23 PM »
Use the existing Event system. Attach a UIEventTrigger script to your button in the inspector. Add your script and method with its one parameter in the OnPress event. You pass an object to the parameter and select a property from it. I use a super simple script that just has a public int attached for things like level selection, and I pass that as a parameter in the UIEventTrigger parameter.

So I have two scripts on a level selection button, UI_Number that just has a public int, and UIEventTrigger that passes this int value to the script.