Understanding Translate
To actually use these variables to move an object, we will use the Translate command. When implementing any piece of scripting, you should make sure you know how to use it first.
Translate is a command which is part of the Transform
class: http://unity3d.com/support/documentation/ScriptReference/Transform.html.
This is a class of information that stores the position, rotation, and scale properties of an object, and also functions that can be used to move and rotate the object.
The expected usage of Translate
is as follows:
Transform.Translate(Vector3);
The use of Vector3
here means that Translate
is expecting a piece of Vector3
data as it's the main argument—Vector3
data is simply information that contains a value for the X, Y, and Z coordinates; in this case coordinates to move the object by.
Implementing Translate
Now let's implement the Translate
command by taking the h
and v
input values that we have established, placing them into Vector3 within the command.
C# and...