- Home /
Make C# Class Globally Available on JavaScript
Lets say I have a class written in C#. Now I want to use it in many of my JS files. Is there a way to make it globally availabe, without the need to call
var theClass = GameObject.Find("SomeObject").GetComponent("C# Class")
each single time?
I'm not sure I understand your usage of the term 'globally available'. Wouldn't you have to use GetComponent to get a reference to an object, even if you could see the class? Are you trying to make JS classes talk to C# classes in a type-safe way?
I mean that, independently of which Script I am coding in, that I could simply type:
theClass.someStaticStuff
Ins$$anonymous$$d of
var theClass = GameObject.Find("SomeObject").GetComponent("C# Class")
theClass.someStaticStuff
In other words: to make the class name a global variable (such as the JS classes do).
I think you misunderstood the meaning of class. And I don't get what you mean by 'make the class name a global variable such as JS classes do'.
$$anonymous$$ryptos: No, I'm sure. Just think of it as placing the name from the namespace of script in one language (in this case, C#), into the namespace of others (in this case, JS files). I could simply set them as static values on every script (and connect them on "Awake"), but I am trying to understand if there is no better way to do it.
robbiek: No, I am interested in making a class, not a function, global. Because the namespace of scripts in different languages does not appears to be shared (the standard API is, but everything you define in one language is not available on the other).