It’s the same as GetButton and GetKey. I’m not sure how I’m suppose to show my work for this. First off though, there is a big difference, GetButton/GetKey return a bool(the button is either pressed or not pressed). While GetAxis returns a float value between negative one and positive one. You set up axes in the input manager. Where you can change the dead, snap, gravity, and sensitivity of it. Vertical and horizontal axises can be used.
Here is the code they used:
public class AxisExample : MonoBehaviour
{
public float range;
public GUIText textOutput;
void Update ()
{
float h = Input.GetAxis("Horizontal");
float xPos = h * range;
transform.position = new Vector3(xPos, 2f, 0);
textOutput.text = "Value Returned: "+h.ToString("F2");
}
}
This was their example for using both Axises
public class DualAxisExample : MonoBehaviour
{
public float range;
public GUIText textOutput;
void Update ()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
float xPos = h * range;
float yPos = v * range;
transform.position = new Vector3(xPos, yPos, 0);
textOutput.text = "Horizontal Value Returned: "+h.ToString("F2")+"\nVertical Value Returned: "+v.ToString("F2");
}
}