Hello,
Ive got a class named Building_Script and a class named UI_Script.
Ive added a namespace named Buildingsytem to the Building_Script and want to say:
using Buildingssystem in my UI_Script class. That works
So heres the Question:
How can i say using Buildingsystem.Building_Script;
I wanna be able to write in UI_script Gameobject(from Building_Script).transform.position… instead of writing everytime Building_Script.Instance.Gameobject.transform.position…
Is there any way to do that?
ps(edit): i know i could do:
GameObject obj = Building_Script.instance.obj;
but thats not what im searching for cuz i would have to do that for like 20 objects…
When i do using BuildingSystem.Building_Script it sends an error message because building_script is a class
Thanks
As long as you understand the lifetime implications of copying variable references, you can make a local variable to point to any part of that construct. (Edit: as the Lurking Ninja has dashed in and posted above!)
Just understand that if something else changes any of those properties, then depending on if it is a value or reference type that you have chosen to cache in your local variable, you need to understand if it gets updated or not.
It seems you confused what a namespace is and what a type is. Your class is a type, not a namespace. Types live inside namespaces. You can import namespaces but not types. There is the “using static” statement which can be used to map the static members of a type into the global namespace. However I would strongly recommend to not use it. It might makes some sense to import certain static libraries if you use them very often. Though when using a using static statement you may introduce ambiguity.
This of course assumes that “Gameobject” is one of your own instance field / property of your “Building_Script” singleton. Note that if you really named your field Gameobject, that was already a bad move to start with. If by “Gameobject” you meant to write “gameObject”, you can already shorten your code by just doing
Building_Script.Instance.transform.position
You have to do that for 20 object? Does that mean you have like 20 singletons? This seems to be a fundamental design issue in this case.