how to disable "raycast target" of a created gameobject in unity2d

Viewed 87

I want to generate a description label on an object when the mouse enters it. However, the generated description blocked the mouse and immediately triggered the OnPointerExit event for the object. For some reason, I don't want to turn off the raycast function in prefab, so how can I turn it off in code?

public void OnPointerEnter(PointerEventData eventData)
{
    _desc = Instantiate(prefab, this.transform);
    var bg = _desc.transform.Find("BG");
    if (bg != null)
    {
        //What should I do?
    }
}
0 Answers
Related