C#C
C#3y ago
Odin

❔ GetAxis wont work

public class Driver : MonoBehaviour
{
// Start is called before the first frame update
const float MoveUnitsPerSecond = 5;
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");

// Update is called once per frame
void Update()
{
//move game object as needed
Vector3 position = transform.position;
if (horizontalInput != 0)
{

position.x += horizontalInput * MoveUnitsPerSecond *
Time.deltaTime;

}
if (verticalInput != 0)
{

position.x += verticalInput * MoveUnitsPerSecond *
Time.deltaTime;
}
transform.position = position;

}
} Why wont GetAxis work, the course i am going off of has this exact code but unity is saying that I cannot call GetAxis("Horizontal") from a monobehavior constructor
Was this page helpful?