Player Advantage? Enemies Destroy The Power-Ups! (Part 1)

Enemies and power-ups spawn and are respectively destroyed or collected by the player. But would an enemy really let the player collect a power-up? No! They’d destroy it before that happened!

A basic Anti-Powerup Laser!

I’ll add a new variable to the Enemy Gun script:

This will add a small cool-down between shots, so that it isn’t shooting at a power-up every single frame.

I also create a new function inside Enemy Gun:

Now inside the Else, I’ll check if there’s a Power-up in front of this gun, and if there is, shoot the laser:

I have 2 guns on the enemy ship, so I’m going to duplicate this code to do a raycast from the 2nd gun too

Add a call to the new function into the existing Update method.

The Anti-Item Laser fires independently of the regular laser

Moving to the Powerup script, I’ll add to it’s OnTriggerEnter2D function:

It should now fire as soon as a Power-Up is detected in front of it:

Ignore the buggy flickering of the ship

In Part 2 of this post, I will be making an advanced version that can target any powerup on the screen, as long as it is vertically lower than the enemy!

Up the challenge! Check it out tomorrow!

--

--

--

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

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

Recommended from Medium

USSD Handling React-Native

Revisiting unidirectional data flows on Android with Kotlin’s SharedFlow and StateFlow

Toss A Coin To Your W-… Security Guard. (Part 1)

Android Fundamentals: Communication in Android

Android Fundamentals : Broadcast Receivers

Asynchronous Android : Kotlin Coroutines

Android Data Binding : Dynamic RecyclerView Adapter

Integration of Account kit and Audio kit in ‘Land of Calm’ Application

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
Vincent Taylor

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

More from Medium

The Fourth Player Challenge: Problem Solving and Jumping

Platformer: Death Animation

Adding Fog to the HDRP Pipeline in Unity 2020

What is a Control Track in Timeline