How to Swap Action Maps

Let’s take a look at how we can go about changing our action maps through script. To start, we will create a few actions for 1 map.
The first action we will create is the ability to change the colour of a cube to a random new one by pressing the space key:

Once we have our simple colour change process built, we can test it within the editor:

Next, let’s go about building the ability to rotate our cube to the left and right by holding down a or d:

Now, to test it out:

As we can see, there is a slight issue. When we go to hold down the key, it will rotate in the wrong direction. In order to fix this, we can add in an invert setting to our processors:

Now that we have our cube rotating around properly, let’s build in a new action map and the logic for Unity to switch between the 2:

What I have done is created a simple button action in both the player and the drive state. These actions are in place to just change our player from the different states. Now, once we have set up our driving state the move around when using WASD, we can test to see if we have the different actions in the states:

There we have it. We have built in the logic to allow the player to have different states depending on the situation they are in for the game. This allows us to program multiple actions for the same key.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store