Multiple variables in a function? Like function test (number : float , number1 : float)
As I said in the question I want to declare multiple variables in a function like :
function test (number : float , number1 : float , number2 : float)
{
//Do things
}
But that doesn't work. (error if I try to call it from another function and I can't set that function to a button).
Please be more specific. The error is there to tell you what is wrong but you are not telling us what the error is.
This code compiles just fine and logs out "works! 1, 2, 3" as expected ,so there's nothing wrong with the code you posted.
function Start () {
test(1,2,3);
}
function test (number : float , number1 : float , number2 : float) {
Debug.Log("works! " + number + ", " + number1 + ", " + number2);
}
You just have to make sure you have written all 3 parameters to every line of code that calls this method.
You can't directly add this method to be called from a button because you can't define 3 float parameters into a button callback. Buttons can only call functions with a string parameter or no parameters. For example in my example, you can make the button call Start(), which in turn calls test() with some parameters you define (you'd better rename the function to something else or it'll get confusing though)
Your answer
Follow this Question
Related Questions
Using variables without overflow 0 Answers
Variables and Functions {Tutorial Question} 1 Answer
Passing variable name into function from different script/animation event editor 0 Answers
How to pass a game object through to a function? 2 Answers
How to run a function without certain input variables? 0 Answers