Hey guys, I wasn’t sure where to put this thread but I figured this topic would be the most convenient. I really like programming in java, and lately I’ve been messing around with combining Java and JavaScript. I’ve tried to make the .js into a class, and then in the .java file I did
test javascriptfile = new test()
javascriptfile.dosomething();
and then I tried to compile it while my unity game was running. This returned two errors from my compiler, both saying that it couldn’t recognize the “test” class. I have also tried making the .js file a .class file instead, but this turned out to be really stupid because unity isn’t good with .class files If anyone knows anything about this, or knows where to read about it, please make a post! I would be really glad.
Issue #1 being that Java and UnityScript (Unity’s JavaScript implementation) both are JIT run, but one on the Java Virtual Machine, and the other using CIL. This means that they likely cannot easily communicate at compile time (unless you built your own Java interpreter) and even outside of that you’d need to run two JIT compilers and pass back and forth. This would likely be both expensive and difficult to manage.
Underneath the name, and some syntax similiarities, Java and Unity’s JavaScript have very, very little in common.
Agree. Syntax wise they are pretty similar even though there are some notable differences, especially with the ways classes are organized and some other smaller stuff (i.e. events). Most notable may be the class scope.
Hmm ok thanks guys but actually I just thought it would be awesome if I could communicate with unity using Java @Ntero, I know Java and JavaScript have little in common, but I just thought that maybe it would be possible to combine the languages without too much struggle. I have no clue how to make a compiler and it sounds like it wouldn’t be worth while.
You know, I kind of asked the same question that you did. The way I see it both Unity Web and java components actually share a common bond… but it is not fast, nor friendly… It’s called Javascript… The real Javascript, not Unity Scipt, but a web page.
My question was how to get Unity to talk to a web page, and get a web page to talk to unity. As far as I known, Java applets talk to web pages, so through Javascript, you can communicate information.