- Here's an example with two arguments and a non-void return value
- The
return
keyword tells what we return from the functionfloat Pythagoras(float a, float b)
{
float c = Mathf.Sqrt(Mathf.Pow(a,2) + Mathf.Pow(b,2));
return c;
}
- The function is called like this:
float length = Pythagoras(3f, 4f);
- The function definition can be further simplified...
float Pythagoras(float a, float b)
{
return Mathf.Sqrt(Mathf.Pow(a,2) + Mathf.Pow(b,2));
}