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. Dismiss Notice

uGUI Button - wire up the click...?

Discussion in 'Immediate Mode GUI (IMGUI)' started by DrCrook, Aug 24, 2014.

  1. DrCrook

    DrCrook

    Joined:
    Mar 3, 2014
    Posts:
    13
    Hello,

    I'm working on my LD48 entry and am trying to figure out how to wire up the click handler for the new uGUI stuff.

    Any tutorials out there? I'm not quite following the process.

    Thanks,
    ~David
     
  2. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,033
    One of the simplest ways is to just add a new MonoBehaviour with an OnClick() method. Add this component to a gameobject, hook it up to the On Click() under the button.

    Example:


    Code (csharp):
    1.  
    2. public class Click : MonoBehaviour
    3. {
    4.    public void OnClick()
    5.    {
    6.       Debug.Log("Click!");
    7.    }
    8. }
    9.  
    The script is just added to the button itself.
     
  3. caseyboundless

    caseyboundless

    Joined:
    Oct 17, 2011
    Posts:
    590
    I can't get it to let me use the same script but a different button with a different function.