Project
Beginner Gameplay Scripting
GetAxis
Tutorial
Beginner
5 Mins
Unity Technologies
Overview
You have completed 0% of this Tutorial.
1.
GetAxis
Summary
How to "get axis" based input for your games in Unity and how these axes can be modified with the Input manager
Language
English
Recommended Unity Versions
4
1.
GetAxis

AxisExample

using UnityEngine; using System.Collections; 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"); } }

AxisRawExample

using UnityEngine; using System.Collections; public class AxisRawExample : MonoBehaviour { public float range; public GUIText textOutput; void Update () { float h = Input.GetAxisRaw("Horizontal"); float xPos = h * range; transform.position = new Vector3(xPos, 2f, 0); textOutput.text = "Value Returned: "+h.ToString("F2"); } }

DualAxisExample

using UnityEngine; using System.Collections; 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"); } }

Woohoo! You nailed this tutorial.
Continue rocking your Beginner Gameplay Scripting project.
Next Step:
OnMouseDown
Tutorial
Beginner
5 Mins
Unity Technologies