Phase 2: Ammo UI

Objective: Create a visual representation of the players ammo

Following on from the last post, we will now add the ammo UI elements in a similar way as the thrusters fuel level. We add the neccessary UI element inside the canvas (UI Image) then set the source image. Inside the UIManager script, create a serialized image and a serialized sprite array. Move to the inspector and set the images for the ammo is the correct order from sprite 0 up with zero being no ammo. for this case add one extra sprite for when the chaos powerup is in effect as we have a special sprite with a power color to use for the duration of the powerup.

Inside the UIManager script we edit the previous UpdateAmmo method to set the UI Image to the Sprite array value of the ammo. We add an isChaosActive bool that is activated in a public ChaosActive method that has the bool value passed from the player script when activated and deactivated. Inside the Update ammo we check to see if Chaos is active and use the special ammo sprite in this case and if not use the sprite variant to match the ammo.

ChaosActive and UpdateAmmo public methods
Ammo UI with Chaos Active Demo

In the next post, we will look at adding a negative collectable





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

Recommended from Medium

Android 13 will make it possible for you to easily open notifications in split-screen

How to Use the Paging 3 Library in Android

Unconfined Enums Adapter for Moshi

Let’s Explore Jetpack DataStore

Phase 1: Camera Shake

Better dependency management in Android Studio 3.5 with Gradle buildSrcVersions

Dagger Hilt in 3 Minutes

Firebase Dynamic Links With Flutter

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
Simon Leen

Simon Leen


More from Medium

Coroutines in Unity

Eyesight in Unity

Quick tip — Enabling post-processing in Unity Universal Render Pipeline

Unity’s Tilemap System