OnPointerEnter And OnPointerExit Not Working In Unity

134 views Asked by At

I'm trying to make an Android FPS Game in Unity; It was good until I get to the Looking Input code. Here what I tried:

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

public class LookInput : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
    public Vector2 lookInput;
    public float smoothTime = 8f;
    public float sensivity = 3f;

    Vector2 lastPosition;

    int touchIndex = 0;

    // Start is called before the first frame update
    void Start()
    {
        touchIndex = -1;
    }

    // Update is called once per frame
    void Update()
    {
        if (touchIndex != -1)
        {
            lastPosition = Vector2.Lerp(lastPosition, Input.touches[touchIndex].position, smoothTime * Time.fixedDeltaTime);

            lookInput = (Input.touches[touchIndex].position - lastPosition) / 10 * sensivity;

            GameInput.lookInput = lookInput;
        }
    }

    public void OnPointerDown(PointerEventData data)
    {
        touchIndex = data.pointerId;
    }

    public void OnPointerUp(PointerEventData data)
    {
        touchIndex = -1;
    }
}

But it didn't work.

I Also tried

override

for OnPointerDown & OnPointerUp. But it gave me some Errors:

Assets\LookInput.cs(36,26): error CS0115: 'LookInput.OnPointerDown(PointerEventData)': no suitable method found to override Assets\LookInput.cs(40,26): error CS0115: 'LookInput.OnPointerUp(PointerEventData)': no suitable method found to override

Thanks. (Sorry if English is bad)

0

There are 0 answers