Input not triggering, nothing working

I’ve been trying to get this working for over an hour now :(.

I have a file called InputManager. It’s attached to a rect transform that’s part of my ui canvas. Neither of the print functions are being called.

using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;

public class InputManager : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IDragHandler, IEndDragHandler
{
    public PlayerManager playerManager;         //A link to the Player Manager
    public void OnPointerDown(PointerEventData eventData){
        print ("HELLOOOO??");
        setPosition (); // is this necessary?
    }
    public void OnBeginDrag(PointerEventData eventData)
    {
        //playerManager.UpdateInput(true);
    }
    public void OnDrag(PointerEventData data)
    {
       print ("Anyone out there?");
        setPosition (); 
    }
    private void setPosition()
    {
        Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        playerManager.setPlayerPositionTo(pos);
    }
    public void OnEndDrag(PointerEventData eventData)
    {
 
    }
}

Here’s a picture of the event system (potentially could be problematic).

Script looks fine. In order for OnPointerDown to function, you have to:

  • Click in the rect area defined by the RectTransform on the object it’s attached to.
  • Rect area must not be hidden behind other UI elements, which are blocking raycasts.
  • Have a Graphic Raycaster attached to the parent canvas.
  • Have that graphic raycaster allow raycasts, and allow raycasts for the layer the child object belongs to.
  • This script, the GameObject it’s attached to, and all GameObjects up the hierarchy from this GameObject must be enabled.
1 Like