Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Multiple Canvas' with buttons - onclick doesn't work

Discussion in 'General Discussion' started by rajaleneweit, Mar 17, 2020.

  1. rajaleneweit

    rajaleneweit

    Joined:
    Oct 24, 2018
    Posts:
    29
    Hello, dear community,
    I have 3 canvas' in my game, two of those contain a button and one contains raw image. All have render mode screen space - camera. Now, my problem is that I can only click one of the buttons, the other button does not react to clicks anymore. I already tried giving different layers orders, so 0 for one canvas, 1 and 2 for the others, but did change anything. It worked fine before I set the render mode to screen space.
    Here are my canvas settings:

    How do I fix that?

    Edit: Solved. I found out that I didn't have Raycast Target enabled on the second button. If you have the same problem, that one button works and the other one does not althought you have an onclick added, first compare the settings of both buttons. Maybe you clicked somewhere accidently without noticing it.
     
    Last edited: Mar 19, 2020
  2. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,801
    Put all buttons on one layer. If you need to turn them on and off do so by myButton.gameObject.SetActive(true)
     
  3. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    611
    Also, please try to post in the correct section the next time, which in this case would be UGUI or General Support.

    Thanks :)
     
  4. rajaleneweit

    rajaleneweit

    Joined:
    Oct 24, 2018
    Posts:
    29
    Thank you for your reply. I found out that the problem was that I didn't have "Raycast Target" enabled on the second button. Everything works fine now.
     
    Kiwasi and ippdev like this.