Why GetAxis expects a string instead of enum?
Hello there!
I'm new to Unity (and game developing in general), but I do have some experience in coding. I was watching a few videos and reading the documentation when I saw the following method:
Quite often I see methods and classes (in games) that aren't "aligned with the best coding practices", such as using global variables and whatnot... But usually it makes sense, since such "best practices" often incur in a performance penalty.
But in this case... Why use a string instead of a enum? Enums are safer and more performant, as far as I know.
Answer by doublemax · Sep 27, 2016 at 10:25 AM
I think the main reason is that hardcodes values for axis and button names can be difficult among different devices and platforms. Therefore it's configurable under "Menu -> Edit -> Project Settings -> Input". This makes it also easy to allow the user to remap the controls.
Applying certain names to axis can also make your code more readable.
Your answer

Follow this Question
Related Questions
Best practices to reduce Unity WebGL load times on Facebook 1 Answer
Guide for pixelating particle effects using render textures 0 Answers
These two standard examples platforming demonstrate the best practices? 0 Answers
Unity MVC animation coroutine 0 Answers
Best way to create a universal notification pop-up? 0 Answers