Why is it that in some example projects, the same programmer uses C# scripts and Javascript scripts at the same time? Is it because of functionality differences? I have been thinking of this for a while but could not have a clue.
Thanks in advance!
Why is it that in some example projects, the same programmer uses C# scripts and Javascript scripts at the same time? Is it because of functionality differences? I have been thinking of this for a while but could not have a clue.
Thanks in advance!
Flavor. JavaScript/UnityScript offer much cleaner code for coroutines for example where others prefer C# since they knew it before they came here, or they enjoy the syntax better. There are ups and downs with both languages. I wouldn’t worry too much of which language one would pick for personal use, but there often comes a slight headache as soon you start mixing the languages in a project.
I am mainly a C# guy. I prefer the elegance JS offer for some things, like coroutines. That said, I don’t use JS in my professional work other when I have to use with thrid party code. Mostly because I love Visual Studio & C# in general.
C# support extension methods, where JS does not. That said it is still possible to call the methods in a more verbose way in JS. This makes C# more ideal when working with Linq, or other systems that benefit from extension methods.
JS allow implicit assignment (not sure what the term is for that) when you for example want to do something like this:
// Fine in JS, but not in C#
transform.position.x += 1;
// C# way:
Vector3 temp = transform.position;
temp.x +=1;
transform.position = temp;
Probably because the programmer isn’t very experienced and only knows how to do certain things in each language.
But to answer your question- the main difference in unity for C# and Javascript/UnityScript is generics. Most casual unity developers aren’t even going to know what that is, so for all intents and purposes, nothing ![]()
I dont think I am a casual unity developer, but I don't really understand what you're saying about generic differences. Would you care to elaborate a bit?
– StatementYou can't declare generics in JS, only use (instantiate) them. It's one of the few things I use C# for, since I prefer the cleanliness and clarity of JS code. I do however use #pragma strict since I definitely don't want the looseness JS allows otherwise. As you say, it can be a headache mixing, so I only have "plugin" type stuff (indeed, in Plugins/) in C#, not project-specific stuff.
@statement, okay great! Your previous statement (excuse then pun) sounded like a misunderstanding, hence why I went to the trouble to answer. :)
– Bovine
Yes, that javascipt feature is quite handy - I'm forever having to make copies of transform.position! :)
– Bovine