A calculate function

I’m new to unity and I’m not sure if this is possible but can you do something like this

public var result : float;

Calculate(5,3)

function Calculate () {

the first number imputed - the second number imputed = result; }

So I can input any 2 numbers in a calculate function and the result variable will equal the first number imputed minus the second number imputed. So in the example above the result would equal 2.

I know this example has no real purpose, I just want to know if something like this is possible.

Change your calculate method to this:

public float Calculate(float num1, float num2)
{
 return num1-num2;
}

Thanks, I slightly changed your code to what’s below, so now it works fine.

public var result : float;

result = Calculate (5,3);

function Calculate(num1 : float,num2 : float) { return num1-num2; }