5

I would like an authoritative answer on a point that has been a question mark for me for a little while. There seems to be a frequent use of the term JavaScript to mean or describe UnityScript.

I have been told time and again that you can use actual JavaScript to develop games in Unity, however from what I understand UnityScript could, at best, be described as a superset of JavaScript, but there really are some items that perhaps aren't completely compatible and you can't simply use JS as you normally would to develop Unity games as you would have to follow their conventions.

Am I wrong about this? Can you actually use pure JS and its conventions directly to make Unity games outside of following the parameters that UnityScript has set?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
ylluminate
  • 12,102
  • 17
  • 78
  • 152

1 Answers1

6

Short answer: No you cannot use PURE JavaScript. As far an I am aware - Unity uses it's own JS-like syntax (some people refer to it as Unity JS) but it is most commonly known as UnityScript.

Your question arises from the fact that the Unity community refers to JavaScript and UnityScript as if they are equivalent and interchangeable.

Whilst these look and feel extremely similar - there are some fundamental differences such as UnityScript being class-based whilst JavaScript doesn't support classes.

You can definitely use prior JavaScripting conventions you have picked up within UnityScript as a LOT of it applies. The semantics used are a little different - but I've found it doesn't take long to pick up on the small changes.

Read more about it here: UnityScript versus JavaScript

Happy coding!

maxtuzz
  • 1,945
  • 1
  • 10
  • 7
  • Well, you've essentially related what I had gathered, but... I was hoping to dig a little further and suppose that I need to ask a follow up question at this point. What I really want to get to is whether or not US is a "strict" superset of JS. Ie, can you write UnityScript by following the "limitations" that exist in JS. The reason for this is with regards to leveraging JS as a bridge language into Unity 3D. Ie, can we take another language that compiles to or transpiles to JS and use that as a bridge. – ylluminate Jan 07 '15 at 02:29
  • 2
    I would say that they are different enough that one cannot be considered a subset or superset of the other. The only similarities I can recall (I haven't used UnityScript in a while) is its C-like syntax, use of `var` for variable declarations, and use of `function` for function declarations. Many JS features that you would rely on are simply compilation errors in US, and many required aspects of syntax for US are errors in JS. – Zach Thacker Jan 07 '15 at 15:34