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.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What I have learned In My First Week Undergoing IGHUBFellowship4.0 Program.

Youku’s Digital Practice in the Supply Chain of Long Video Content

A true story about Magento extensions (unfortunately) based on real events

Word Break Coding Question

Deploy NGINX Plus Ingress with App Protect to Secure a Juice-Shop App in the AWS EKS Cluster

Print names of test methods executed by JUnit 5

DIY: Complete cycle of data research

Firebase Android

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
Jordan Evans

Jordan Evans

More from Medium

Scripting Actions (New Unity Input System)

Creating a Physics Based Character Controller from Scratch in Unity

OnCollisionEnter Vs. OnTriggerEnter — When to use them?

Improving Upon Selection Highlighting in Our Game — Part 3