Does not implement Interface Member

Hi. I’m fairly new to C# so I’m still getting used to it. I’m also new to the forums so I apologize if I’m doing anything against the rules. This is actually the first of my most probably multiple threads. I’ve been following tutorials online and trying to understand everything as much as I could. But honestly, I’m mostly just copying the codes on the videos I’m watching. I’ve had this code going where I want to control a character with a virtual joystick. I was testing whether the joystick would be responsive or now, but every time I try to play the scene, I get 3 CS0535 errors saying:
-VirtualJoystick' does not implement interface member UnityEngine.EventSystems.IPointerUpHandler.OnPointerUp(UnityEngine.EventSystems.PointerEventData)’
-VirtualJoystick' does not implement interface member UnityEngine.EventSystems.IDragHandler.OnDrag(UnityEngine.EventSystems.PointerEventData)’
-VirtualJoystick' does not implement interface member UnityEngine.EventSystems.IPointerDownHandler.OnPointerDown(UnityEngine.EventSystems.PointerEventData)’

Here’s the code. It’s fairly short.

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

public class VirtualJoystick : MonoBehaviour, IDragHandler, IPointerUpHandler, IPointerDownHandler
{

private Image bgImg;
private Image joystickImg;
private Vector3 inputVector;

private void start()
{
bgImg = GetComponent();
joystickImg = transform.GetChild(0).GetComponent();
}

public virtual void onDrag(PointerEventData ped)
{
Vector2 pos;
if(RectTransformUtility.ScreenPointToLocalPointInRectangle(bgImg.rectTransform, ped.position, ped.pressEventCamera, out pos))
{
Debug.Log(“Test”);
}
}

public virtual void onPointerDown(PointerEventData ped)
{
onDrag(ped);
}

public virtual void onPointerUp(PointerEventData ped)
{

}

}

I hope you guys could help me through this. Thanks.

Well, something I’ve noted is you’re calling methods: onPointerUp and such, while it should e OnPointerUp (yes big O matters).
Also public void OnPointerUp(EventSystems.PointerEventData eventData) while your implementation says it’s virtual, try removing that.

1 Like

Of course, error on the Syntax. Thanks for pointing that out. I got it to play the scene after fixing it, but there was this NullReferenceException error when I was testing it with the Log saying: NullReferenceException: Object reference not set to an instance of an object. What should be my next step here?

Can’t really help without knowing what object is causing the exception and what scripts affecting it.

Well this is kind of embarrassing. I managed to fix everything with some messing around. Thank you again, Serveros for pointing out that error in syntax. I’m such a n00b. or whatever kids today call it.

Yes it’s really true the big “O” is really different from small “o”. I’ve tried it and it really works. Thank you for this forum you saved me!