- Home /
getting a variable from a c# script with a Js
there are scripts in my game that are writen in c# i switch writing methode to java script and i was wondering if its possible to get a variable from a c# script with a java script and the other way around?
Answer by Ray-Pendergraph · Oct 08, 2011 at 01:28 PM
GetComponent will get you any component UnityScript or otherwise. Here are some caveats to this:
1) UnityScript and C# components are not accessible to one another in the same compile phase. Check this link out for more info on that. In other words if you want to treat the thing in the calling code as its type and not just UnityEngine.Component (not very useful).If you have to have them in the same phase for some reason you maybe could use reflection... I have done this with a UnityScript component from C# but not sure about the other way around. I steer away from UnityScript.
2) UnityScript does not understand C# properties so you will have to use the "get_" for the property, expose a method, or make the backing member public.
3) Just remember that UnityScript and C# "scripts" are all just .NET classes underneath. So access is pretty much straight forward. Ivars must be public to get to them.
Your answer
Follow this Question
Related Questions
is not a member of 'UnityEngine.Component' 1 Answer
passing variable from javascript to C# 1 Answer
trying to set a javascript variable from c sharp 1 Answer
Accessing JavaScript variable from C# and vice versa. 3 Answers
C# GetComponent 3 Answers