- Home /
Writing with c# and javascript simultaneoulsy
Hey guys what's up? I code with javascript but understand well c#. I'm following the unity stealth tutorial and since it's written in c# translating it into js is pretty hard. So I was wondering if I can use both languages simultaneously. Since unity works in both languages can it convert the scripts from one to another so they can both work together?
Unityscript is terrific and very natural for Unity3D. This has been said over and over: the fact is you need to be pretty good at both. I don't think there's any way around that, ultimately be fairly good at both of those, for Unity. the fact is Unity is "bilingual."
Its lack of features make working with it difficult, not simple. Your response tells me that you don't actually know C# well, and I recommend you go check out what it uniquely offers in Unity.
Good point Fattie =]
Here is my generic C#_JS post : Here's some links I found useful in converting between C# and JS :
http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html
http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/
Edit : though absolutely as whydoidoit states, you should only use one language per project.
Answer by ahaykal · Apr 22, 2013 at 03:49 PM
Well you can use them together, everything will work normally but you have to know which script you want to compile first. A lthough from my personal experience I prefer to use only one language (Preferably c#).
Unity doesn't convert the scripts from one to another, however you can use this to convert from C# to unity-script.
I just tested it. Can't believe a converter actually works. Thanks alot mate
Answer by Julien-Lynge · Apr 22, 2013 at 03:43 PM
Yes, you can absolutely use both simultaneously. The caveat is that if you're going to communicate cross-language, you need the class you're going to call to be compiled first. For example, if you have MyCS.cs and you want to call a method in MyJS.js, MyJS.js has to be compiled in an earlier step than MyCS.
You can get a list of the compilation steps here:
http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html
10x bro. apparently they were right. C# is more powerful then js
Answer by Bunny83 · Apr 22, 2013 at 03:56 PM
It's very easy to convert UnityScript to C#. Take a look at my answer on this question
Watch out: Coroutines can't be decompiled to C# due to some tricks the compiler does when it's compiling them.
Just FWIW. A useful common trick is:
You'll have some c# class sitting in Plugins. Because it's in Plugins, basically your Unityscript can call it no problem.
But, you want to "get back to" your unityscript world. You want to call something in the Unityscript world.
It's almost always easiest to just do this ..
public class BlahBlah : $$anonymous$$onoBehaviour
{
public static event Action<string> informationIsReadyEvent;
.. blah blah..
void someFunction()
{
if( informationIsReadyEvent != null )
informationIsReadyEvent( stuff, stuff );
blah blah
}
then over in your unityscript land, inside some .js file ...
function Awake()
{
BlahBlah.informationIsReadyEvent+= aNormalFunction;
}
then you merely do this
function aNormalFunction( height:Float, fatness:float )
{
blah blah ...
}
the function aNormalFunction() will run completely normally whenever you call informationIsReadyEvent up in the c# codebase.
I hope it helps you or some other readers!
Thanks bro. that's gonna help alot when it comes to jumping from c# to js & vice versa
right. often "all" of your scripts are unityscript, and important stuff is c# - in the plugin folder! this is how you get "back" to the unityscript, often.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How can i make the ray cast don't go through the walls 1 Answer
Add force to GameObject 2 Answers
BCE0044: expecting }, found 'private'. PLEASE HELP!!!!! 2 Answers
Why isn't my word generator working? 1 Answer