Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

One solution to: "How to detect if button is pressed?"

Discussion in 'UGUI & TextMesh Pro' started by Gurunext, Nov 2, 2014.

  1. Gurunext

    Gurunext

    Joined:
    Jan 23, 2013
    Posts:
    9

    NOTE: needed to reupload the video... that's what I get for not editing/testing them

    This stuff is annoying to deal with (just like every "work around" thing) and after Unity developers will take notice it's going to be annoying to see how useless my work was, just like what happened to my GUI system, but it's all for the better, the skills i've gained from this have left. In addition to this thing I also use my own scaling to have the best fit for the screen, but I am not going to expand on that.

    Alright I've rewriten the code once I've found out that "OnPointerxxxxx" works with mobile devices.
    I've put up a cool example of how I am able to detect if the button is highlighted or pressed. I don't know if I should work on pressed color/animation/sprite being used for other two mouse buttons.

    These examples (ButtonPress.cs & ButtonHighlight.cs) consist of already built-in simple examples that will work once script will be attached as a component. ButtonPress.cs contains Hold event as well as Down/Up/Release. Release is not Down as it's invoked if button is not being Hold. ButtonHighlight.cs contains Highlight/Lowlight (Every frame) & Enter/Exit (Trigger) events.

    I think it is going to be useful to seal this question once and for all (so link here so people would find a detailed answer).
    P.S. Let me know once Unity gets a new feature to know what state button is at ;)
     

    Attached Files:

    Last edited: Nov 2, 2014