Time for action – controlling functions with parameters
Our functions now communicate back to us, but we still haven't communicated to our functions; that's where input parameters come in. Declaring parameters in your function declaration requires the presence of one or many values, without which it couldn't function. For instance, if we wanted our MoveObject
function to move the target game object to a different distance each time we called it, we could make that distance one of the required parameters, so each function calling MoveObject
will need to tell it how far to translate. Perform the following steps for controlling functions with parameters:
Remove the declaration for
translationValue
on the top line of theMoveObject
function and declare a distance parameter, as shown in the following code:float MoveObject ( float translationValue ) { gameObject.transform.Translate(translationValue, 0.0f, 0.0f); return translationValue; }
We can still refer to the variable
translationValue
because...