Search Unity

Stopping an "Update Selected" Event Trigger (my dirty solution)

Discussion in 'UGUI & TextMesh Pro' started by rattlesnake, Mar 30, 2015.

  1. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Good morning here :)

    I'm trying to move a cube while I left click on a button.

    I could achieve that with a simple combination of Pointer Down/Pointer Up with a boolean... but as I have a tons of buttons I would like to simply my code.

    So I found that launching my moveCube() function throught an "Update Selected" Event Trigger is working very well.
    Then you can stop the loop by clicking once again somewhere else.
    But how to stop it with a "Pointer Up" ?

    I found a dirty solution (i don't even understand why it's working) , but I would like a cleaner one :)

    Here is the dirty way :
    - Add a "Pointer Up"
    - Object = "eventSystem"
    - Function = TouchInputModule/DeactivateModule

    Thanks in advance.
     
    RisingDead_xTR likes this.
  2. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Nobody ?
     
  3. Ramcat

    Ramcat

    Joined:
    Aug 16, 2014
    Posts:
    95
    Maybe if you shared this code people could comment on the code. I'd love you to share it because I'm trying to add a pointerDown and pointerUp event to a button and can't find an example.
     
  4. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Hi Ramcat,
    I'm not using code here, but the inspector,

    Here is the procedure :
    - Add a button

    On that button :
    - In the inspector, add an Update Selected (Base Event Data).
    Select the function you want to launch (Ex : a translating function)

    - In the inspector, add a pointer Up (Base Event Data),
    Parameters :
    Object = "eventSystem"
    Function = TouchInputModule/DeactivateModule

    This will break the translating function.

    But it's clearly not a proper way to do it...
     
  5. tigereno

    tigereno

    Joined:
    Feb 25, 2015
    Posts:
    1
    I had the same problem then applied your method and it worked. I don't know how but thanks!!!
     
  6. kubajs

    kubajs

    Joined:
    Apr 18, 2015
    Posts:
    58
    Setting eventData.selectedObject to null in any handler method (e.g. IPointerUpHandler.OnPointerUp) will unselect the object and the OnUpdateSelected method won't be called anymore (until you make another mouse click / mouse down).

    Code (CSharp):
    1.  
    2. void IPointerUpHandler.OnPointerUp(PointerEventData eventData)
    3. {
    4.     eventData.selectedObject = null;
    5. }
    6.