C
C#16mo ago
Derpwizee

Make a method acessable by scripts extending it, but not by outside scripts

I have private which limits a method to itself, and I have public which lets anything access the method given it has access to an object of the script. Is there a way to set it so a method can be accessed by scripts extending it, but not by any other outside scripts? An attempt at a google didn't give me the anwer i needed
33 Replies
Servator
Servator16mo ago
internal?
Servator
Servator16mo ago
Access Modifiers - C# Programming Guide
All types and type members in C# have an accessibility level which controls whether they can be used from other code. Review this list of access modifiers.
Derpwizee
DerpwizeeOP16mo ago
No, I need it to be two seperate scripts
Angius
Angius16mo ago
There's no "scripts" in C# There are classes, projects, etc
Derpwizee
DerpwizeeOP16mo ago
Two separate files
Angius
Angius16mo ago
And files in C# don't matter in the slightest
Derpwizee
DerpwizeeOP16mo ago
cat extends animal type of thing
Angius
Angius16mo ago
So we're back where we started Classes, then
Derpwizee
DerpwizeeOP16mo ago
Yes good sir
Angius
Angius16mo ago
In which case, as has been said already, use the internal modifier
Servator
Servator16mo ago
wait looks like i got it somehow These 2 classes in same solution/project ?
Derpwizee
DerpwizeeOP16mo ago
Yes If it helps i'm using Unity
Servator
Servator16mo ago
then its internal
Angius
Angius16mo ago
For the record, if your question is related to Unity, do mention it first and foremost
Derpwizee
DerpwizeeOP16mo ago
But wouldn't that be a class localised inside another class?
Angius
Angius16mo ago
Unity uses it's own weird modified outdated version of some odd fork of Mono or whatever And forgoes many things common for proper C#
Servator
Servator16mo ago
Is it class in a class or different 2 classes?
Angius
Angius16mo ago
You didn't read the docs on internal, did you?
Derpwizee
DerpwizeeOP16mo ago
2 different classes
Servator
Servator16mo ago
like @ZZZZZZZZZZZZZZZZZZZZZZZZZ said read little bit it wont hurt
Angius
Angius16mo ago
internal modifier on a class member makes that member available to all classes that inherit from it And not to any outside code
Derpwizee
DerpwizeeOP16mo ago
But doesn't internal mean that it's a class made inside another class?
Angius
Angius16mo ago
No
Angius
Angius16mo ago
There's no special modifier for nested classes, even RTFM
Thinker
Thinker16mo ago
you... mean protected... right?
Angius
Angius16mo ago
Oof, right internal is for assembly, innit?
Thinker
Thinker16mo ago
yep
Angius
Angius16mo ago
I so rarely use them I get them confused lol
Thinker
Thinker16mo ago
and assemblies don't exist in Unity
Derpwizee
DerpwizeeOP16mo ago
Looks like someone needed to read their own docs they sent
Angius
Angius16mo ago
In that case, yes, protected
Derpwizee
DerpwizeeOP16mo ago
Thank you
Want results from more Discord servers?
Add your server