Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

MouseInteraction component: over state for touch screen

Discussion in 'Project Tiny' started by reallyhexln, Apr 18, 2019.

  1. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Hi guys.

    I use the MouseInteraction component to determine mouse click / mouse over state for some UI element.

    Unfortunately, when I trying to use touch input with MouseInteraction component, I get some strange result for the over state while pressing some UI element.

    Code (JavaScript):
    1. this.world.forEach([ut.UIControls.MouseInteraction], (input) => {
    2.     console.log("over: " + input.over);
    3. });
    over: true
    over: false
    over: false
    over: false
    over: true
    over: false
    over: false
    over: false


    Do you experience such issues?
     
    Last edited: Apr 18, 2019
  2. SAFWANEGAMES

    SAFWANEGAMES

    Joined:
    Sep 10, 2017
    Posts:
    2
    Hi .
    To Detect Mouse Click You have to Use .

    1. this.world.forEach([ut.UIControls.MouseInteraction], (input) => {
    2. if(input.clicked)
    3. {
    4. // your function here .
    5. }
    6. });
     
  3. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Hi, SAFWANEGAMES, I know about that.
    Unfortunately, I need to have ability to check over state of some UI element (I use some custom logic to change the behavior of element when the mouse / touch over it).
     
  4. Pakor

    Pakor

    Joined:
    Feb 2, 2017
    Posts:
    32
    It seems like what is happening is that touch input does not actually record the mouse over event. You said it only went to true when you clicked the UI element right? It seems (from my experience) that tiny links the click event to the Over event when the input is touch. I don't know how you could solve that, since phones just don't have an Over event as far as I know
     
    reallyhexln likes this.
  5. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Thank you for your response, Pakor.
    I have used "IPointerEnterHandler" from the UnityEngine before, and it constantly returned "true" for "over" state while the button was hold. Unfortunately, Tiny do not follow such rule, and return "true" only for the first frame when the button is pressed (it returns "true" for each 4 frame when the button is pressing, if be precise).

    UPD:
    I will try to use HitBox to detect "over" state when using touch screen. I hope, HitBox has no problem with detecting "over" state.
     
  6. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    131
    What's your use case for having an "over" state for touch? In touch mode, you can't have "over" without having "down".
    So depending on your use case, you could just only check for the mouseInteraction.down.

    I would advise against using the HitBox method, as that is relatively performance-heavy.


    On a sidenote: I did notice that when I have two buttons in my scene and press and hold my finger on one button, then (while still keeping my finger on the screen, so the first button is still "down") move my finger to the other button, it does the "over" state correctly.
     
    reallyhexln likes this.