Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    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

    WilliamDaniels

    Joined:
    May 27, 2018
    Posts:
    33
    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

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    352
    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?