OnPointerClick only triggers when clicked on the top part of UI Image
Hi, I have a problem with the onPointerClick event. It only gets called when I click on the top part of the image. I have no clue why this is happening. The EventSystem should be set up properly as buttons do work. I was wondering if anyone could help me, please? (The sprite of the image of the prefab is set from code after instantiation if that might have to do anything with this but I'm not sure if it does.)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class CharacterItem : MonoBehaviour, IPointerClickHandler {
public int price;
public int id;
public bool owned;
// Use this for initialization
void Start ()
{
this.GetComponent<UnityEngine.UI.Image>().color = new Color32(100,100,100,255);
}
void OnEnable()
{
this.GetComponent<UnityEngine.UI.Image>().color = new Color32(100, 100, 100, 255);
}
// Update is called once per frame
void Update ()
{
if (owned)
{
this.GetComponent<UnityEngine.UI.Image>().color = new Color32(255, 255, 255, 255);
}
}
public void OnPointerClick(PointerEventData eventData)
{
if (this.owned)
{
if (ABManager.ab.SetSelectedCharacter(id))
{
this.transform.parent.parent.GetComponent<SortCharacters>().menu.GetComponent<Menu>().ChangeOpt(0);
}
}
}
}
I finally found the solution. A text object that is a child of Char 0 had too much height so it interfered with the image, that's why the raycast didn't happen, I fixed it by decreasing the height, now everything is fine.
Answer by tucsok007 · Nov 27, 2018 at 03:22 AM
Okay, so I've got to the conclusion that this is happening because the anchored position of the object is modified by a script, I'm still not sure how to fix this tho, if anyone has an idea, please help. :)
Your answer
Follow this Question
Related Questions
Count and find NON-PERSISTENT UnityEvent listeners: How? 1 Answer
How to pass event info to events? 1 Answer
Help with Unity Events 0 Answers
ScrollBar and scrollrect seem not working on mobile 0 Answers
Making UI block rays with touch inputs 0 Answers