When I searched for “function” in the script reference section it came back empty…
Is it possible to assign default values to arguments of a function, or can this only be mimicked through overloading?
How do we know if we are passing variables by reference or by copy?
(I know as a general rule for JS for the web - basic variables are passed by copy and objects / complex variables are passed by ref.)
Are there differences between Boo C# and JS when it comes to these things?
That’s because these questions are not particular to Unity, they’re particular to the language you chose (Boo, C#, Unityscript/Javascript). Which language are you developing your code in?
I’m currently working with JS just because of the familiarity I have with it.
If it comes down to C# can offer more control over how variables get passed via reference or copy, I’m gonna switch over.
I like how JS is less redundant, I find I can think better when there’s less code to look at, but I’m not going to overlook functionality if it helps to optimize the code.
private var y=3;
private var z=4;
function x(y, z){
return y+z;
}
function x(){
return x(y,z);
}
function x(y){
return x(y,z);
}
function Start () {
print(x());
print(x(5));
print(x(5,6));
}
You can’t assign default values; overloading works.
Classes are passed by reference, structs are passed by value. In C#, you can specifically define ref and out parameters. In JS, you can’t declare ref/out parameters in functions, though you can use C# functions that contain these. (This is the main reason I use C# for library functions. Otherwise I use JS for everything else.)
Is there a place in the manual for language specific details and syntax references?
Kind of like the PHP manual (man was that thing ever loaded with details)
No, the Unity manual only covers Unity topics. See MSDN for C# docs. See here for Boo docs. Unityscript (Javascript) is somewhat trickier. The JScript.NET docs on MSDN (note: not plain JScript, but JScript.NET specifically) covers 95% of it. There’s some discussion in the Unity 3 docs about new features for Unityscript, such as generics, that don’t exist in JScript.NET (but which do exist in C#). The wiki has some Unityscript docs too.
To actually learn C# I would recommend something different–invest in a book on the subject! For example: Jesse Liberty’s “Learning C# 3.0” (a typical animal book) and the “Head First C#” (a new approach).