Search Unity

Question Game Object is not seen in Event System Raycast

Discussion in 'UGUI & TextMesh Pro' started by mjozdi, Feb 25, 2023.

  1. mjozdi

    mjozdi

    Joined:
    Mar 25, 2020
    Posts:
    1
    Hi
    I'm new at unity and I'm trying to do very simple thing. As you can see there are only two object in my scene under Canvas object. This is the script I added both Ground and Deneme objects.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.EventSystems;
    5.  
    6. public class Ground : MonoBehaviour, IPointerClickHandler
    7. {
    8.    
    9.     public void OnPointerClick(PointerEventData eventData)
    10.     {
    11.        Debug.Log("Ground clicked");
    12.     }
    13.  
    14.  
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.                
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.    
    25.        
    26.     }
    27. }
    I wanted to see ground clicked when I click on the ground object. But it doesn't seen. Console stays empty when I click on ground. But when I click on "Deneme" Image object, console says "Ground clicked."

    I wondered why it works on deneme object and doesnt works on the ground. So I looked at EventSystem. Raycasty doesnt simply detect ground object. It has a boxcollider 2d.

    So why can it be happening?
     

    Attached Files:

  2. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    try adding the IPointerDown and IPointerUp interfaces as well...

    I dont recall atm for sure, but there is a few of those events that actually require all of the appropriate interfaces implemented.

    Also- as that is probably not affecting you with it 'partially' working, you may need a graphics/physics raycaster.