function printOther (t : String)
what does the area in red mean above? I understand what simple functions without data in the parenthesis do, but I don’t get what happens when you write things inside the parenthesis.
function printOther (t : String)
what does the area in red mean above? I understand what simple functions without data in the parenthesis do, but I don’t get what happens when you write things inside the parenthesis.
This is a JavaScript (UnityScript) function declaration.
t, is a variable name
The “: String” refers to the type that t must be when calling.
So:
var bob:String = "Bob";
function Start(){ printOther(bob); }
function printOther(t : String){ Debug.Log(t); }
Will print “Bob” to the debug log.
I guess I just dont undestand why you would ever have to type something in the (). Like why can’t you always create a function like this:
function Running ()
{
print(“I am running”);
}
and whenever you want to call the function, you just type the name, Running() wherever needed. What is the advantage of further declaring things between the ()? Can’t you just type all of the commands between the { } and use it that way?
That’s a bit of an ironic question since the example you gave has a function with a parameter.
Namely:
print("I am running");
How would they code that function if it didn’t have a parameter? If you made your own print function, it would look like this:
function print (s : String) {
Debug.Log (s);
}
And of course the Log function also takes a parameter. You need parameters in order to pass data into functions.
–Eric
whatever is between the parentheses of a function is whatever parameter that function is accepting.
Have a read:
I think I am grasping what you are saying. I am going to read further and post back because I am confused with bigmisterb’s code still. Specifically line 3.
Start is a function that is inherent to Monobehaviour, Monobehaviour is what Unity runs all your objects on. It is a Behaviour for your object. you code functions and variables into them. They have some default ones for you to use.
Look at the Overridable functions section.