Member-only story

How to use Unity’s new Input System to simplify and expand your game’s controls

This guide will show you how to stop using if-else statements for player controls with Unity’s new modern approach

Dusk Sharp
6 min readDec 28, 2020
Create games with awesome control schemes quickly and easily! Photo by Glenn Carstens-Peters on Unsplash

If you are a Unity game developer, how many times have you started your game project by writing the Player GameObject’s controls? Nothing gets motivation rising like seeing a Capsule or Cube move when you press the keyboard’s arrow keys. A few if-else statements lead to some working movement.

How often have you seen or even written code like this for your player movement?

if(Input.GetKeyDown(Keycode.A)){
// move left
}else if(Input.GetKeyDown(Keycode.D)){
// move right
}else if(Input.GetKeyDown(Keycode.W)){
// move up
}else if(Input.GetKeyDown(Keycode.S)){
// move down
}

Don’t get me wrong, this works fine for some games. But what happens when you want to add projectile fire? Then you want to add some melee weapon attacks, what then? Your player has to drive a car through a course — how do you set up the new controls so they don’t interfere with the old? Wait, you also need controller support?!

As you can see, programming inputs gets a little messy once you get past the basics.

--

--

Dusk Sharp
Dusk Sharp

Written by Dusk Sharp

Indie Game Development and Trends in Gaming

No responses yet