Search Unity

Two Function on a single Button

Discussion in 'UGUI & TextMesh Pro' started by kingmujo, Aug 13, 2017.

  1. kingmujo

    kingmujo

    Joined:
    Aug 7, 2017
    Posts:
    13
    Hi Guys!

    is there a possibility (if yes how?:p) to put two functions in a single ui button ?
    for example i have two animations: anim1: standing still table, anim2: rotating table.

    i want a "start/stop" ui button...

    at beginning the table stands still(cuz of anim1) and the button says "start"...
    when i click the button it calls my anim2, the table starts rotating and the button says now "stop"...
    when i click the button again it calls my anim1, the table stops rotating and the button says now "start"...
    and so on ...

    how can i solve this problem ?
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    It's not really a "problem" per-se
    You just need a behaviour script linked to the click event of the button. In that script you have a bool value that is changed when you click, then based on that bool, you change the view / action of the button.

    I did some similar things with the new Cooldown button in the UIExtensions project (link in signature) which should help. I'll see about adding this style of control to the project as well.