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
internal?
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.
No, I need it to be two seperate scripts
There's no "scripts" in C#
There are classes, projects, etc
Two separate files
And files in C# don't matter in the slightest
cat extends animal type of thing
So we're back where we started
Classes, then
Yes good sir
In which case, as has been said already, use the
internal
modifierwait looks like i got it somehow
These 2 classes in same solution/project ?
Yes
If it helps i'm using Unity
then its internal
For the record, if your question is related to Unity, do mention it first and foremost
But wouldn't that be a class localised inside another class?
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#
Is it class in a class or different 2 classes?
You didn't read the docs on
internal
, did you?2 different classes
like @ZZZZZZZZZZZZZZZZZZZZZZZZZ said read little bit
it wont hurt
internal
modifier on a class member makes that member available to all classes that inherit from it
And not to any outside codeBut doesn't internal mean that it's a class made inside another class?
No
There's no special modifier for nested classes, even
RTFM
you... mean
protected
... right?Oof, right
internal
is for assembly, innit?yep
I so rarely use them I get them confused lol
and assemblies don't exist in Unity
Looks like someone needed to read their own docs they sent
In that case, yes,
protected
Thank you