How do you manage multiple If Statements

4 weeks ago 35
ARTICLE AD BOX

I am currently coding a project with many numbers of If Statements to check certain values. I feel like that all those statements seem inefficient and time-consuming in my program. How can I optimize or manage this in some way.

Note: I am not experienced in C# and may not understand many concepts.

Example in Raylib C#:

if (Raylib.IsGamepadAvailable(0) == true) { // looking around on gamepad rotationV.X = Raylib.GetGamepadAxisMovement(0,GamepadAxis.RightX) * rotationS; rotationV.Y = Raylib.GetGamepadAxisMovement(0,GamepadAxis.RightY) * rotationS; // move on gamepad left joystick if (Raylib.GetGamepadAxisMovement(0, GamepadAxis.LeftX) < 0) movementV.X *= movementS; if (Raylib.GetGamepadAxisMovement(0, GamepadAxis.LeftX) > 0) movementV.X *= movementS; if (Raylib.GetGamepadAxisMovement(0, GamepadAxis.LeftY) < 0) movementV.Y *= movementS; if (Raylib.GetGamepadAxisMovement(0, GamepadAxis.LeftY) < 0) movementV.Y *= movementS; } else { // rotation on mouse rotationV.X = Raylib.GetMouseDelta().X * rotationS/10; rotationV.Y = Raylib.GetMouseDelta().Y * rotationS/10; // move on normal controls WASD if (Raylib.IsKeyDown(KeyboardKey.W)) movementV.Y *= movementS; if (Raylib.IsKeyDown(KeyboardKey.S)) movementV.Y *= movementS; if (Raylib.IsKeyDown(KeyboardKey.A)) movementV.X *= movementS; if (Raylib.IsKeyDown(KeyboardKey.D)) movementV.X *= movementS; movementV.X *= 0.1f; movementV.X *= 0.1f; }
Read Entire Article