Search code examples
androidtouchunity-game-enginengui

Call a touch function using NGUI/Unity3D?


I have a game that is using GUITextures for buttons but it isn't working on different resoltutions. So I was told NGUI would do it very easily. But I already have the code written for the GUITexture buttons.

How do I do it for NGUI buttons using the same textures? I've searched everywhere and can not find any answers....the NGUI forums are not much help.


Solution

  • Your Gameobject should have any type of collider component then in script do the following:

    //Use UIEventListener to bind your gameobject with your desired method 
    
    public GameObject YOUR_BUTTON_GAMEOBJECT;
    
    UIEventListener.Get(YOUR_BUTTON_GAMEOBJECT).onClick += YOUR_METHOD_NAME;
    
    
    //METHOD SIGNATURES 
    void YOUR_METHOD_NAME(GameObject gameObject){
         //On Click Stuff
    }
    

    Hope this helps