Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Unity UI Cant detect if pointer is over UI buttons

Discussion in 'Unity UI & TextMesh Pro' started by WilliamDaniels, Jun 13, 2018.

  1. WilliamDaniels


    May 27, 2018
    Hi, i have a UI which is a background and title. I also have another UI with a button to toggle music. When the user touches the screen, it fades into level one.

    At the moment its running that function even when i click on the music button which i dont want.

    The go to would be this:

    Code (CSharp):
    1. if ((Input.touchCount > 0) && Input.GetTouch(0).phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
    2.     {
    3.             StartCoroutine(loadNextLevel());
    4.     }
    But as the background is also part of the UI, this will not work because ill always be over a UI element.

    Ive looked for ways i can target specific UI elements but i cannot get anything working.

    I did also have the idea to have a variable called buttonClicked that will be true when the button is clicked and then only go to the next level when its false but unfortunatly the button click event runs after the next level function
  2. Hosnkobf


    Aug 23, 2016
    If I understand it correctly you have two Canvases and probably two Event Systems which are displayed at the same time... and they both work independently. And you want not to click two buttons (one in each of the canvases) at the same time. Is this correct?

    I am not sure if this actually would work as I described it... But if this is the problem, why don't you use the same Event System for all UI?