Graphics Reference
In-Depth Information
// get fire / action buttons
Fire1= Input.GetButton("Fire1");
}
The script calls its own update function from LateUpdate(), which is where Unity
recommends all input checking happen:
public void LateUpdate()
{
// check inputs each LateUpdate() ready for the next tick
CheckInput();
}
}
Note that if firing does not work after applying this script, check that Unity is set up correctly
to receive mouse button input as Fire1. To do this, open up Unity's Input menu (Edit Project
Settings Input) and check that the Axes entry for Fire1 contains an entry for mouse 0 either
in the negative, positive, or alt buttons.
4.7.2 Single Axis Keyboard Input
The single axis keyboard input script takes away the vertical axis and only takes input
from horizontal and fire inputs. It follows the same format as the other input scripts and
the input script from Chapter 3 (Player Structure), except the vertical axis is excluded:
public class Single_Axis_Keyboard_Input: BaseInputController
{
public override void CheckInput ()
{
// get input data from vertical and horizontal axis and
// store them internally in vert and horz so we don't
// have to access them every time we need to relay input
// data out
horz=Input.GetAxis("Horizontal");
// set up some Boolean values for up, down, left and right
Left =(horz<0);
Right =(horz>0);
// get fire / action buttons
Fire1=Input.GetButton("Fire1");
}
public void LateUpdate()
{
// check inputs each LateUpdate() ready for the next tick
CheckInput();
}
}
Search WWH ::




Custom Search