C# - Error " does not implement interface member"
Hey guys,
I'm getting an error in my code that I don't understand. Any ideas on how to fix this?
Assets/OnClick_Button_Canvas.cs(11,14): error CS0535:
OnClick_Button_Canvas' > does not implement interface member >
UnityEngine.EventSystems.IPointerClickHandler.OnPointerClick(UnityEngine.EventSystems.PointerEventData)'
using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using System.Collections; using TriviaQuizGame; using TriviaQuizGame.Types; using UnityEngine.EventSystems; using EasyWiFi.Core; using System;
public class OnClick_Button_Canvas : MonoBehaviour, IPointerClickHandler
{
public Button buttonPrefab; //default button
public TQGGameController tqgameController;
private int index = 0;
bool isPressed;
public void OnPointerClick(PointerEventData data, ButtonControllerType button)
{
isPressed = button.BUTTON_STATE_IS_PRESSED;
if (isPressed)
{
Debug.Log("Button Clicked");
tqgameController.ChooseAnswer(index);
}
else
Debug.Log("Button Released");
}
}
Answer by tanoshimi · May 08, 2016 at 05:11 PM
You've got the signature wrong for OnPointerClick. It should be
OnPointerClick(PointerEventData eventData) { ... }
See http://docs.unity3d.com/ScriptReference/EventSystems.IPointerClickHandler.OnPointerClick.html
Also note that the error message is giving you this information.
Answer by musicartslao · Apr 16, 2019 at 09:37 AM
I have the same issue here in version 201837 too ! I was using a coroutine to pulse and drag an object, my error message being: "MyEventHandlers.cs(10,47): error CS0535: 'MyEventHandlers' does not implement interface member 'IPointerEnterHandler.OnPointerEnter(PointerEventData)'"
But if you check my snippet:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//01
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
//02 add extra handlers
public class MyEventHandlers : MonoBehaviour, IPointerEnterHandler, IDragHandler, IPointerExitHandler
{
//04 to make the object pulse, check if it is pulsing already
private bool pulse = false;
//04a and keep track of the time
private float time = 0;
//03 for IPointerEnterHandler, IDragHandler, IPointerExitHandler....
public void OnDrag(PointerEventData eventData)
{
//
//throw new NotImplementedException();
//06b update the position of the object to the position to the mouse pointer in order to drag it with the mouse
this.gameObject.transform.position = Input.mousePosition;
}
public void OnPointerEnter(PointerEventData eventData)
{
//
//throw new NotImplementedException();
//06 starts the coroutine
pulse = true;
StartCoroutine(PulseObject());
}
public void OnPointerExit (PointerEventData eventData)
{
//
//throw new NotImplementedException();
//06a set pulse
pulse = false;
}
I do implement IPointerEventHandler !
Your script does not throw such error in an empty project. Try
Closing and reopening Unity
Right-click on the script file + Reimport
Close Unity, delete the
Library
folder next to yourAssets
folder, open Unity again