Day 36: Shield Strength

Objective: Allow for multiple hits to the shield

To start, we will need a reference to the current strength the shield has and the max. We need a max so the player can’t collect 100 shields and be invincible. We’ll create the variables on the player script.

Where we assign the bool _isShieldActive, is where we would want to check to if we are at max shield strength or not. If we aren’t at max add one to it.

We add to the strength of the shield, now it’s time to take away. In the damage method, when the player gets hit we’ll check to see if the shield strength is more than 0 and return.

That’s how we give the shield strength, but now time to show some visual of the strength. Today, we will talk about adjusting the alpha of the shield to show the strength. We’ll start off by grabbing the Renderer from the shield.

Now we have a reference to the renderer, we will need a new method. The reason for a new method is, the method will be called from two different locations, when we collect the shield power up and when the player gets damaged. We don’t want to have the same code in multiple spots.

We’ll call the method ShieldDisplayStrength. Inside it we will use a switch statement. For each case of the shield strength we’ll change the current shield color to a new one with a different alpha.

Now that we have the method done, we need to call the method for it to work. Where we add to the strength is a good place to call this method.

The other place to all it would be where the player gets damaged.

This where give the player some feedback on how strong his shield is! You now have a shield that can be stronger and a display to show it.

--

--

--

I am passonate on learning to program and use Unity to become a skillful Unity Developer

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

Recommended from Medium

Guide for Mastering Modern JavaScript skills

CS 373 Spring 2022: Saran Chockan Blog # 7

A Brief Intro to Ahead-of-Time (AOT) Compilation in Angular

old-fashioned alarm clock pointing to seven a.m.

Running Sitecore in Docker Containers within an Enterprise Environment

Helpful Tips and Tricks: Chrome DevTools

Naming Convention in Angular

Creating a React Calendar Component: Part 3

Javascript solving last page issues(JS 處理上一頁相關問題)

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
Tyler Smallwood

Tyler Smallwood

I am passonate on learning to program and use Unity to become a skillful Unity Developer

More from Medium

Day 101: Character Animation Part 4

Creating a Loot system (part 1)

Adding a Main Menu to our UI

Camera plugin for Unity