Journal 147 — Unity Project Development, 2.5D Shooter

Objective: Fix Option menu to adjust audio, brightness, and difficulty

In the previous articles, I had set up the Main Menu and Options Menu, but there was no functionality in the Options Menu. I’ll go over how I fixed this.

Options Menu

I started with adding UI Scaler game objects. I’ll use a mix of float values and integers.

Volume Slider

To fix the volume slider, I referenced this article. I started by viewing the Audio Mixer under Window/Audio. I made a new AudioMixer called “GameAudio”. When I view the properties in the Inspector, I right-click the Volume component and select “Expose ‘Volume (of Master)’ to script”.

After exposing the volume to script, I can set a custom name for this to refer to. In this case, I’ll call it “VolumeParam”.

I made a new Volume Slider script and attached it to the Volume Slider. I made a variable for the GameAudio Mixer and attached it to the script. In the script, I have a function to change the volume level via a logarithmic equation, and I also save volume level to PlayerPrefs in a new variable I created.

In the OnValue Changed Component, I can set the dynamic float to the attached script’s function.

Now let’s see this in action.

To implement this, I can go to the Main Game scene, and update the audio sources (Player bullets, sound effects, background music) and add the “Master “ GameAudio Mixer Group to override their audio volume.

Brightness Level

For the brightness, I decided to use a UI image over the game screen. At maximum brightness, the UI image will be completely transparent with an alpha of 0. At lowest brightness, the alpha value of the image will be set up to 0.4.

In the slider, I will save the slider value to PlayerPrefs.

Over in the game scene, I added a script to the UI image to reference the saved brightness value.

Now let’s see this in action.

Difficulty Level

For the difficulty level, I set up three whole number values in the slider, with 0 being the easiest level. For the difficulty levels, I’ll change enemy speed, bullet speed, and enemy rate of fire.

In the enemy base script, and the bullet scripts, I used a switch statement to first pull from PlayerPrefs the difficulty level, then I checked the difficulty level and changed enemy speed and enemy bullets. I kept the player speed and the player’s bullets untouched.

Now let’s see this in action.

Thank you for your time!

I have additional articles planned to go over refinements to the movement and effects, weapons, and UI.

--

--

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