Search Unity

Resolved Disable event from game to UI

Discussion in 'Scripting' started by Monkey_M, Dec 29, 2020.

  1. Monkey_M

    Monkey_M

    Joined:
    Mar 10, 2020
    Posts:
    36
    Hi guys,

    I apologize in advance but, I have read several answers around but they don't seem to work for me.
    The problem is this:
    In my game I keep my finger pressed in the center of the screen.
    At some point (while my finger is always resting) I enable a ui component which has a button in exactly the same place.
    So if I now move my finger to another area and release nothing happens. if I release my finger at the same point, the onClic function of the button is enabled.
    I don't want this. I want the key to be activated only if it is pressed and released.

    also this happens on android while on unity everything works as it should.

    Some idea?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,734
  3. Monkey_M

    Monkey_M

    Joined:
    Mar 10, 2020
    Posts:
    36
    Hi Kurt-Dekker, thank you,

    I did some tests and I think it works but I couldn't make the script I just simulated it with timers.
    Could you give it a last hand?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,734
    Just do something like this in your Update() loop, a separate script ON the actual blocker object:

    Code (csharp):
    1. void Update()
    2. {
    3.    if (Input.touches.Length == 0)
    4.    {
    5.       gameObject.SetActive( false);
    6.    }
    7. }
    Every frame that will check if there are any touches of any kind anywhere, and the moment there are none it turns off the GameObject that it is located on. Obviously, put it on the blocker that covers your buttons.
     
    Monkey_M likes this.
  5. Monkey_M

    Monkey_M

    Joined:
    Mar 10, 2020
    Posts:
    36
    Fantastic now everything works fine!
    Thank you so much for your help and your time
     
    Kurt-Dekker likes this.