- Home /
All Game objects behind the button is also getting click
I have this button that's on top of a game object that function when getting click, if the button is on top why the game object behind works like its also getting click. OnClickHide() is the function of the button.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Displayer : MonoBehaviour { private GameObject itemDisplayer;
void Start()
{
itemDisplayer = GameObject.Find("ItemDisplayer");
}
public void OnClickHide()
{
itemDisplayer.SetActive(false);
}
}
Answer by Gcreator22 · Jun 10, 2019 at 09:37 AM
Fix it I use IPointerClickHandler on the object behind and add 2d raycaster to the main camera. If you have any other suggestion fell free to comment i,ll just leave this here.
Your answer
Follow this Question
Related Questions
Problem with button On Click 1 Answer
When using AddListener, can multiple buttons be registered to the same function? 1 Answer
Smoothly rotate while holding 1 Answer
Word Game in Fungus 1 Answer