So I have have a script for a text mesh on a 3D text in unity and I want it to access a variable from a cube that has an OnMouseDown function, inside that function it changes the score and i want that score to be outputted into the text. the cube script is wrote in javascript while I wrote the text script in cs. Anyone have any ideas?
-
1Consider providing the code related to your question to get a better, precise answer.anonymous– anonymous2015-06-07 23:12:13 +00:00Commented Jun 7, 2015 at 23:12
-
1I'm pretty sure you can do it the standard way. Have you tried GetComponent<Type>().whatever? Otherwise send a message to the object with the variables you want. Message handling should bridge the gap between JS and CS.Reasurria– Reasurria2015-06-08 06:57:14 +00:00Commented Jun 8, 2015 at 6:57
1 Answer
Correct me if i have misunderstood your problem, i might have.
Option 1:
C# Code is compiled before js code, which means you dont have access to any classes / types written in javascript from c# code. However scripts located in a folder called Plugins is compiled before the "game code", so you could move js script in to a folder called Plugins and then have access to its types from C# code.
This is a kind of hacky approach (if it's not a plugin it should not be located in a folder called Plugins) but it would work.
Option 2:
Access whatever you need from the js file via reflection during runtime. I won't reccomend this though, because reflection is usually slow. Tricks can be done to speed things up thoguh.
Only choose this option if you absolutely insist that the javascript file should not be convertet to c#, or located in a Plugins folder.
Option 3:
Convert the javascript file to c#. This is what i would recommend.