create custom function

Hey,

I have a question about function. So I know how to create a basic function and how to call it. Smth like this:

function Start()
{
myFunction();
}

function myFunction()
{
//do what ever I want
}

But I have seen a few times function where you can input a value like

function Start
{
myFunction(myValue,anotherValue);
}

So actually I wanted to ask how I have to set up my function so that I can input the value and how it will return the value to the previous function. I couldn’t find anything on in the Unity docs so I don’t really know where to look it up.

1 Like

It's not really a Unity question, it's a basic programming question, so just look up pretty much any programming tutorial regarding functions. (ActionScript3 tutorials would be good for Unityscript since the syntax is very similar, more so than Javascript.)

1 Answer

1

Hey there,

Basic awnser to your question (in C#, which I greatly recommend)

void Start()
{
    MyFunction(20,"Sergio");
}

void MyFunction(int aNumber, string aName)
{
    Debug.log("Hello : " +aName+" you are " +aNumber+" years old.");
}

So you must match pass the parameters with the proper type and the proper order to make it work.

Hope it helps !

Claude