- Home /
C# Class Does Not Implement Interface Member
I'm having some issues with my OnPointerClickString Class. When I tried to implement IPointerClickHandler and ISubmitHandler I got two errors saying OnPointerClickString does not implement them. Any ideas why? am I missing a library I need to implement? Did I implement them incorrectly?
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using System.Collections;
public class OnPointerClickString : MonoBehaviour, IPointerClickHandler, ISubmitHandler {
void OnPointerClick(PointerEventData eventData){
Debug.Log("Has Clicked");
}
}
You need to add all the methods from IPointerClickHandler and ISubmitHandler and put them into OnPointerClickString
Ok thanks for the info, you also have to declare the methods public too as I found out.
You only need to make them public if they are public in the Interface. If they are protected in the interface they need to be protected and same with private.
How I'm going to add all the methods from IPointerClickHandler and ISubmitHandler and put them into OnPointerClickString
Answer by jgodfrey · Feb 24, 2016 at 01:34 AM
An interface only contains signatures - so no actual implementation code. If you are creating a class that implements an interface (in your case, your class implements 2 interfaces), you must implement every member in the specified interface(s) within your class.
I don't know what IDE you're using, but Visual Studio has the ability to automatically generate stubs for specified interfaces. That said, you still have to provide the implementation code.
Answer by Dimitrigaming · Jan 11, 2019 at 06:33 AM
you basically have to write each method down before the error will go away so you still need to add
void OnPointerClick(PointerEventData click){
Debug.Log("Has Clicked");
}
void OnSubmit(BaseEventData submit){
Debug.Log("Has Submit");
}