Game Development Reference
In-Depth Information
In the Update function, add the following:
5.
if (animator) {
float v = Input.GetAxis("Vertical");
animator.SetFloat("Input V", v);
print (v); // see what the v input value sent to the animator
}
In this conditional, the code first checks for the existence of the Animator component. It then gets
the current value of the vertical input, the virtual forward key, and assigns it to a variable, v . Using
animator.SetFloat , it assigns that value to the Input V parameter you created in the Animator. The
print line will let you watch to see what the current value of v is as you press and release the forward
and backward keys assigned to the Vertical input.
6.
Save the script.
7.
Add it to the Scarecrow in the Hierarchy view.
8.
Press Play and then press the w or up key to move the scarecrow forward,
watching the console's output as you do.
The scarecrow walks forward while the key is down (Figure 6-37 ).
Figure 6-37. The Scarecrow walking away
 
Search WWH ::




Custom Search