Search Unity

Using buttons on with a helper script

Discussion in 'UGUI & TextMesh Pro' started by Zace666, Mar 26, 2017.

  1. Zace666

    Zace666

    Joined:
    Jan 28, 2014
    Posts:
    21
    I have created 3 different UI canvases in worldspace so I can transition between then by swivelling the camera.

    I now am trying to get the code attached.
    I have an empty object containing the 3 canvases.

    I have created a helper script with things such as startgame, exitprogram. These are defined as public.

    However I cannot see the function in the button when I add an even. I have tried adding the helper script to the empty object and to the canvas (so would have to add it to all 3) but I still cannot see the functions I have written.
    All I always get are GameObject, RectTransform, CanvasRenderer, Image and Button... none of which contain my public functions I have coded. (yes I have saved my work).
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    For the script to be seen by the button in the editor, it simply must be a public function in the script and attached to the game object you have selected.
    There are more constraints for a Dynamic script, where the input parameter for the function needs to match the output type of the control (e.g. a Toggle uses a bool to track it's state, so the function would have to be public dostuff(bool input))

    But for a regular event, like a button, you only need a public function.

    Hope that helps.

    P.S. I'd ask why you have more than one canvas, unless you are using them in different parts of the game.