C# ,I create a interface , how to let the interface be a Component?`It’s the interface,
I want to get it by gameObject.GetComponent(); Can i do it?
\
public interface ISelection
{
void OnSelected (bool isSelected);
}`
C# ,I create a interface , how to let the interface be a Component?`It’s the interface,
I want to get it by gameObject.GetComponent(); Can i do it?
\
public interface ISelection
{
void OnSelected (bool isSelected);
}`
An interface can’t be a Component. Interfaces describes a group of related functionalities that can belong to any class or struct. That means you need to inherit it alongside MonoBehaviour for your scripts.
public class NewBehaviourScript : MonoBehaviour, ISelection
To access it from another component/script, you can do something like
gameObject.GetComponent<NewBehaviourScript>().OnSelected( false );