Using passed function parameters instead of if statements to manage inputs
Hey all, I've been experimenting with 2D platforming in Unity with C#. Currently I am using a list of if statements to handle player input but it is very messy; I thought of a way that would be both cleaner and more efficient but I am not sure how to actually implement it.
Below is some pseudocode of the concept I want to store whatever button is being pressed down and then have the script pass that value to my Control function; upon entering that function, find the section correlated to the input character and execute the associated functionality
Update (){ Char input = Input.getKeyDown(); Control(input); }
Control() { Control(W) Jump functionality
Control(D)
Right movement functionality
Control(A)
Left horizontal movement functionality
} Etcetera
Even a point in the right direction would be much appreciated! What is this concept called, for example?
Thank you
Your answer
![](https://koobas.hobune.stream/wayback/20220612212852im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to have UI Manager come up on collision? 0 Answers
How To Do Basic 2D Movement? 1 Answer
Parsing error? 1 Answer
Player can only jump once!? 0 Answers
Sprites appears corrupted in standalone build, but not editor. 0 Answers