C
C#13mo ago
AdiZ

✅ Quick - Unity "using" directive

Really quick question guys, when trying to use methods from other scripts in Unity, let's say the other script's name (and therefore the other script's class name) is Decoders, do I do using Decoders; or using static Decoders;?
3 Replies
Angius
Angius13mo ago
C# is C# using is for namespaces And lets you use all classes from that namespace using static is for static classes and lets you use methods of that class directly
AdiZ
AdiZOP13mo ago
Ok perfect thank you Because Unity flashed me an error for doing using static but it disappeared when I changed it to using - and now the opposite behaviour is happening when I try to reproduce it - must be a glitch of some sorts.
ophura
ophura13mo ago
when using static is used against a type, it means to import all static members of said type (the type itself is excluded, unless it's been imported by another using). static members include: - nested types - fields with the static modifier - properties with the static modifier - methods with the static modifier - fields with the const modifier it's important to note that the type itself doesn't have to be static. additionally, the use of the using keyword in this syntax:
using NewNamespace = Namespace;
using NewNamespace = Namespace;
or
using NewNamespace = Namespace.NestedNamespace;
using NewNamespace = Namespace.NestedNamespace;
or
using NewType = Namespace.Type;
using NewType = Namespace.Type;
is meant to introduce an alias for a given namespace and/or type. the following however:
using Type = Namespace.Type;
using Type = Namespace.Type;
is used to import a single type rather than define an alias for it, to exclude all other types in said Namespace that might cause ambiguity or some other issues...
Want results from more Discord servers?
Add your server