© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
31 replies
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ "Encryption" wont work
C#CC# / help
3y ago
✅ Why wont my intella sence work
C#CC# / help
2y ago
C# InputSimulator [Some Apps Wont Work]
C#CC# / help
3y ago