1

I'm newbie in Unity3D, I am using NGUI and i don't know how to code a button created from NGUI button. The only code I know is:

void OnMouseDown    
Application.loadlevel(1);

But it's not working in NGUI button. Can someone help me with these simple problem? I'm sorry for asking this small problem of mine, I'm just only a student and beginner, I hope you understand! thank you in advance.

EysAce
  • 17
  • 5
  • 12

3 Answers3

1

You're going to have to use "OnClick" instead. To load the next level on a button click you'd have to add this to the script attached to the game object in question:

void OnClick ()
{
    Application.LoadLevel(Application.loadedLevel + 1);
}

Attach this to your button and it should work.

One thing you might want to do however is to get a centralized script for all your buttons and do a switch case to see which button is pressed, so you don't get a million scripts for each button in your GUI. That would get rather messy really fast!

Tiny
  • 27,221
  • 105
  • 339
  • 599
Chikilah
  • 490
  • 2
  • 8
  • Yes it is. If you need it for javascript it's "function OnClick ()" instead of "void OnClick ()" – Chikilah Dec 21 '13 at 13:03
  • Instead of Application.loadedlevel you need to use Application.loadedLevel i.e. the second 'l' needs to be capitalized. I would recommend taking a good look at intellisense, it will be your best friend while learning! – Christopher B. Adkins Jun 15 '14 at 19:10
0
void OnHover(bool state)
{
 Debug.Log(this.name + " Hover: " + state);
}
void OnPress(bool state)
{
 Debug.Log(this.name + " Pressed: " + state);
}
void OnClick()
{
 Debug.Log(this.name + " Clicked");
 Application.LoadLevel(Application.loadedLevel + 1);
}
void OnDrag(Vector2 delta)
{
 Debug.Log(this.name + " Drag: " + delta);
}
void OnDrop(GameObject droppedObject)
{
 Debug.Log(droppedObject.name + " dropped on " + this.name);
}
void OnSelect(bool state)
{
 Debug.Log(this.name + " Selected: " + state);
}
void OnTooltip(bool state)
{
 Debug.Log("Show " + this.name + "'s Tooltip: " + state);
}
void OnScroll(float delta)
{
 Debug.Log("Scroll of " + delta + " on " + this.name);
}
Oscar Rangel
  • 848
  • 1
  • 10
  • 18
-1

try the following steps:

  1. Go to File-> Build Settings.
  2. Add your scene to it.
  3. A number would be shown.
  4. Either pass the number or the name of the scene in Application.Loadlevel(here).
RIchsa
  • 1
  • 1