Hi so I've came from C so I'm completely new to this class/OOP stuff.
I've been testing out very basic stuff in unity, right now I'm currently implementing sitting on a chair. But I realized the way I implemented it can not be scaled unless i do some Yandere Dev stuff. So, I've been researching and looked into interfaces. But before I actually jump into interfaces, I want to understand how they work so I'm not just blindly using them.
This is what I have gathered but idk if its correct:
-
Interfaces are essentially a universal file that any c# file within the project can interact with and use if they want
-
If a c# script includes said interface in their script (like here: public class playerMovement : MonoBehaviour, IInteractable), it must use the methods within that interface? so if i have for example, open(), close() and use() inside IInteractable, playerMovement must have a function/method called open(), close() and use(), assuming playerMovement is using the IInteractable interface
-
If a script does not use all of methods mentioned within the interface, the compiler will not compile
My brain has decided the following analogy is correct:
- A interface is essentially a psuedo header file in C, if header files worked in a way where you didn't have to include, header files were just universal, and the function inside the header file isnt "linked" to a function within the C file, it just looks for the function in whatever file/script you have referenced
but i've been told this analogy is wrong. I'm wondering if someone can help me conceptualize in a way i actually understand how these things work. Thanks