- Home /
Parent Event Handler Overriding Child Handler
Hey all,
Running into a very frustrating problem. I'm still relatively new to Unity, so apologies if this is an obvious solution.
I have a 2D 'target practice' minigame I'm working on. Here's what it looks like at rest:
There's a Background, which is an Image, which has the script MinigameLogic attached. This script extends IPointerEnterHandler and IPointerExitHandler, along with Monobehavior. It instantiates Target prefabs at a random internval in a Coroutine:
private IEnumerator GenerateTargets() {
for (;;) {
GameObject newTarget= Instantiate(target, transform); //'target' is the prefab
newTarget.transform.SetParent(transform, false);
newTarget.transform.localPosition = new Vector3(Random.Range(-700, 700), Random.Range(-200, 200), 0);
targetsInPlay.Add(newTarget);
yield return new WaitForSeconds(Random.Range(5, 15));
}
}
The Target prefab is an Image with the TargetLogic script attached, which extends MonoBehavior and IPointerClickHandler. The OnPointerClick method looks like this:
public void OnPointerClick(PointerEventData eventData)
{
Debug.Log("Making sure this works!");
}
However, when I click on the instantiated Target, the OnPointerClick method is never called, only the Pointer Enter and Exit events from the parent above.
How can I get the child Click handler to work as well as the parent Enter and Exit handlers? Thanks!
Your answer
Follow this Question
Related Questions
How do you fill an EventTrigger from a script? 0 Answers
Help, Use event system IPointerClickHandler 1 Answer
UnityEngine.EventSystems.. Trying to figure it out .js 1 Answer
How to pass a click through a button? 1 Answer
Setting up EventTrigger programmatically for GameObject throws NullReferenceException 0 Answers