Tips and Resources for a Web Developer Moving to Unity?

Hi guys, new to Unity. I just wanted to ask if there we any resources that would be helpful for someone with a web development background (still a high-school student, but I’ve been doing this for about a year and a half now). I decided to move to Unity after hearing how easy it was to learn, and how powerful it was. I’ve always wanted to learn how to make games, and I tried to learn in the browser itself (WebGL / HTML5 canvas), but I’m afraid my math skills weren’t quite up to it (though I do eventually plan to learn it all).

I already know JavaScript fairly well (I’m no Crockford, but I know what I’m doing. :smile:), and was glad to hear that Unity supported it, though I have a couple questions about that, along with my main question above:

First, what JS engine does Unity use, if it doesn’t use a custom-made one?
Second, what can I expect to be able to do with Unities (Unityes? Unitys?) JS engine? Will all the tricks I know from browser-based engines work in Unity?
Finally, is there any specific modifications to the core JavaScript language I should be aware of (types, C+±style classes, etc.)?

Thanks for any help guys. Really excited to be learning this. :smile:

Edit: I thought I should mention, I have no ‘real’ experience with 3D or 2D games, aside from what I’ve been able to do with WebGL (and that’s not much).

(PS: This looked like the best place to post, as it was mostly about scripting. If it’s the wrong section, I apologize.)

Unity doesn’t really support Javascript. It’s just called that for marketing reasons; really it’s a unique language and should be called Unityscript, though it’s similar to ActionScript 3 or JScript.NET. Basically forget anything about web JS: Javascript vs Unityscript. Unity uses Mono, so you should get familiar with using MSDN as a reference (for example, use this to look up the String class you use in Unity).

Unity’s.

–Eric

Well that sucks. I was hoping to try to use some of the techniques I know from JS in Unity.

Thanks for the link.

Don’t let the differences between UnityScript and JS scare you away though!

Personally I find it preferable to write scripts in C# for Unity. The main “features” are essentially the same and the differences in syntax are actually minor. One of the main reasons I prefer C# is that you can use Visual C# from Microsoft to write your code in. It’s entirely free and will help you immensely with its intellisense and autocomplete features. If you have been using mostly Javascript in your coding life you might not have yet had the wonderful experience of using a quality code-editor… Since C# is a strictly-typed language you benefit a lot from code-hinting etc. Unity now ships with MonoDevelop which is supposedly good too, but I haven’t really delved into it. The project file that Unity creates for MonoDevelop can be opened with Visual C# which enables intellisense and code-hinting for Unity’s classes as well as your scripts.

Code techniques are often transferable from language-to-language, just the syntax varies. In the case of JS → Unityscript the syntax could quite possibly be exactly the same. The differences are not huge.

Well, I’ve also done some basic work in C/C++, and Python, but nothing really fancy, and I don’t really know all of the language, nor more than a small percentage of the libraries.

And I use Notepad++ / vim. :smile:

Can I do this?

// Assume that all the functions / objects exist within Unity, if they already don't.
(function() {
	var localVariable = "Hello,";
	
	var myObject = function() {
		this.publicVariable = "World!";
		this.publicMethod = function() {
			print(localVariable + publicVariable);
		};
	};
	
	game.myObject = new myObject;
})();

myObject.publicMethod();

No, not really. You should really check out the link Eric dropped… UnityScript does not use prototypal inheritance in the way that web js does, every individual .js file in Unity is a class implementation.

Now I remember why I hate Javascript

What!? JavaScript is a great language!

Mmm, oh well. I’ll definitely have to read the link.

Meh…it’s subjective, of course, but I hate it too. Unityscript is far better.

–Eric

After reading up some more on protypical inheritance I can see some advantages to it, particularly in the area of web development. However , for something like a game the classical inheritance model makes more sense (at least to me).

ActionScript 3.0 is interesting because it allows you to do classical inheritance and prototypical inheritance. You can have dynamic classes, functions as objects etc.