Graphics Reference
In-Depth Information
{
TEMPVec3.x=horz;
}
// if we're going up or down, set the velocity vector's X to
// our vertical input value
if(Up || Down)
{
TEMPVec3.y=vert;
}
// return the movement vector
return TEMPVec3;
}
}
2.2.6.1 Script Breakdown
BaseInputController.cs derives from MonoBehavior:
public class BaseInputController : MonoBehavior
{
The input scripts use CheckInput() as their default main update function, which is
intended to be called from the player class. This CheckInput() only contains the very least
amount required for input. It just takes the axis input from the Input class:
public virtual void CheckInput ()
{
The Input class provides an interface to Unity's input systems. It may be used for
everything from gyrometer input on mobile devices to keyboard presses. Unity's input
system has a virtual axis setup, where developers can name an axis in the Input Manager
section of the Unity editor. The Input Manager is available in Unity via the menus Edit ->
Project Settings -> Input.
By default, Unity has inputs already set up for horizontal and vertical virtual axis.
Their names are Horizontal and Vertical, and they are accessible via Input.GetAxis(),
passing in the name of the virtual axis as a parameter and receiving the return value of a
float between −1 and 1. The float variable horz and vert hold the return values:
// override with your own code to deal with input
horz=Input.GetAxis ("Horizontal");
vert=Input.GetAxis ("Vertical");
}
A function is provided to return the value of horz, the horizontal axis provided by
the virtual axis named Horizontal:
public virtual float GetHorizontal()
{
// returns our cached horizontal input axis value
return horz;
}
Search WWH ::




Custom Search