Improving Accessibility in Unity Games – Part 2
- Addressing Motor Disability in Unity Games
- Being Sensitive to Sensitivity
- Enabling the Sensitivity Adjustments
- Adding Rebindable Keys
- Setting Up Your UI Controls
- Testing Your New Settings Window
- Rebinding Your Inventory Controls
- Adding the Rebind Logic
- Finishing Up
- Applying the Rebinding
- Keyboard Navigation
- Fixing Navigation in Other Panels
- Coding the Selection for Each Menu
- Beating Button Mashing
- Preparing CrosshairRay for a Mouse Hold
- Addressing Cognitive Disabilities
- Adding Clues
- Setting Up Your Trigger
- More Fun With Subtitles
- Adding Colors to the Subtitles
- Highlighting Interactables
- Animating Your Interactive Hints
- Switching Between the Regular and Animated Cursor
- Adjusting Your Subtitle Duration
- Making a Slider to Adjust the Subtitle Duration
- Saving the Settings
- Creating a Save Method
- Saving Your Player Settings
- Where to Go From Here?
Welcome back! In part one of this tutorial, you worked on improvements to Puzzley Dungeon to make it easier to play for people with visual or hearing impairments.
In the final part of this tutorial, you’ll learn about even more improvements to help people with motor and cognitive disabilities. You’ll tweak control methods, add a clue system and add quality-of-life changes that all your players will appreciate!
To get started, open your completed project from Part 1 or use the Download Materials link at the top or the bottom of this tutorial to download the Improving Accessibility in Unity Games Part 2 Starter project. Open the starter project.
Addressing Motor Disability in Unity Games
Nerve, muscle and joint conditions have challenging consequences for motor control. Some make fine motor control very challenging, others can limit a person’s range of movement. This can cause problems for gamers.
You can help by building options into your Unity games that give people with motor disabilities more flexibility. For example, every player should be able to adjust the mouse’s sensitivity to suit their needs. And adding remappable keys can help people with limited mobility or those who can only use one hand.
Throughout this tutorial, you’ll see how to use Unity’s built-in tools to make your game as flexible as possible.
Being Sensitive to Sensitivity
If you have problems with fine motor control, being able to change your mouse sensitivity to suit your needs can make a game much more playable. Adding that capability will be your first step to making Puzzley Dungeon more accessible for people with motor disabilities.
To do it, you’ll use Unity’s character controller to expose the multiplier for movement and rotation. Start by selecting the RigidBodyFPSController in the Hierarchy and scrolling down to the Rigidbody First Person Controller component in the Inspector. You’ll see the following public values under Mouse Look:
- X Sensitivity: Controls the mouse rotation from side to side.
- Y Sensitivity: Handles the up and down rotation of the mouse.
Next, you’ll enable some new controls in the Settings panel.
In the Hierarchy, navigate to Canvas ▸ SettingsMenu ▸ SettingsPanel. Select and enable both MouseXSettingComponent and MouseYSettingComponent in the Inspector.
This is starting to look like a real settings menu for a real game! However, those controls don’t work yet.
Enabling the Sensitivity Adjustments
To access Unity’s Character controller, you need to add a namespace to the top of the script. Open the SettingsManager.cs script and add the following
using statement at the top:
Next, add the following variable at the top of the class:
public RigidbodyFirstPersonController rigidbodyFirstPersonController;
This variable holds a reference to the Character controller. Now, you have just two more methods to complete to enable customized mouse sensitivity.
Add the following to the empty
rigidbodyFirstPersonController.mouseLook.XSensitivity = sliderValue;
Additionally, add the following to
rigidbodyFirstPersonController.mouseLook.YSensitivity = sliderValue;
These methods take the values of the sliders and sets the sensitivity values exposed in the Character controller for each axis (X and Y). The
SaveSettings method simply saves the values to the built-in Unity PlayerPrefs store, to persist these settings between game sessions.
There’s one final thing to do before you test your work. Select the SettingsManger in the Hierarchy and drag the RigidBodyFPSController from the Hierarchy to fill the reference on the newly exposed editor field: Rigidbody First Person Controller.
Ok, click Play, head into the Settings Menu and play with the mouse sensitivity. Test it out and see how it affects gameplay. Just try not to make yourself motion sick! :]
Adding Rebindable Keys
Sometimes, default keymappings won’t work for someone with a motor disability. Maybe they can’t stretch far enough to reach a certain key, or they need to be able to reach all the relevant keys with one hand. Allowing players to rebind their keys gives them the flexibility to play their games in a way that works well for them.
Luckily, Unity makes this easy to do because it has a built-in method for rebinding keys when your app is running.
Start by opening the Project Settings menu by selecting Edit ► Project Settings in the toolbar. From this window, select Input from the list on the left. Here, you can assign key bindings and see the ones that Unity has set up out of the box.
By default, the character controller expects the player to use a mouse to look around or to rotate their character. However, for those that can’t use a mouse or who can use only one hand, being able to play your game with the keyboard alone makes your game more accessible.
You’ll need to do a little work on the UI controls to navigate and operate them with the keyboard only.
Setting Up Your UI Controls
Right-click on Axes/MouseX and select Duplicate Array Element. Do the same for Axes/MouseY. You now have two sets of each axis for the mouse movement. You’ll keep one set as is and assign a new control method for the other.
Use the drop-down arrow to expand the new Mouse X and adjust the following:
- Negative button: q
- Positive button: e
- Gravity: 3
- Sensitivity: 3
- Snap: Checked
- Type: Key or Mouse Button
Now, expand the new Mouse Y and adjust the following:
- Negative button: f
- Positive button: r
- Gravity: 3
- Sensitivity: 3
- Snap: Checked
- Type: Key or Mouse Button
These values assign all the movement and character rotation controls to keys that are within easy reach of the ‘WASD’ movement keys.
Testing Your New Settings Window
Build and run your game by selecting File ▸ Build And Run from the Toolbar and you’ll see a lovely settings window for your game.
There are two tabs to adjust settings, one for Graphics and one for Input. This mirrors the settings from the Editor Input menu. Scroll down to see your new key bindings.
This menu allows you to adjust key bindings that will persist between launches. However, right now it only exists between launches of your game and only if the developer enables the menu. You can do better!
Once again… back to the Settings Panel.
Navigate to Canvas ▸ SettingsMenu ▸ SettingsPanel in the Hierarchy and select RebindKeyComponent. Then enable it in the Inspector.