- Home /
Writing functions that return a value
Okay, this is going to be an easy question but one that is taking me far too long to find an answer for.
I am trying to recall the syntax for writing a function that returns a variable, something along the lines of:
private var variable = 42;
function int GetMeaning(){ return variable; }
The Unity reference information, while being fantastic on the classes and functions themselves, doesn't appear to have anything on the actual syntax of Functions, For loops and so on. Is there a reference for this somewhere? So far I have just been copying the syntax used in other scripts I could find that implemented the same methods.
Answer by duck · Apr 17, 2010 at 04:43 PM
Like this:
Javascript:
function GetMeaning() : outputType {
return variable;
}
C#:
public outputType GetMeaning() {
return variable;
}
Cheers! I think this is what happens when I use C# at work and java at home...
Your answer
Follow this Question
Related Questions
Far Clipping Range syntax 1 Answer
How to undo cancel Invoke 1 Answer
Sending a message from javascript to C# 1 Answer
variable = true from another script 2 Answers
Java to C# conversion problem 1 Answer