Enemy destroys power-up if in front

Day 50- Making 2D Space Shooter Game

Objective: Make enemy detect when the power-up is in front of them and shoots laser which destroys the power-up

We are going to add this behavior to the same enemy which could avoid laser and the concept is similar. It will detect gameobjects with tag power-up and fire laser towards it.

add this inside the OnTriggerEnter function so that after the enemy detects the power-up, it will fire laser at it and set the default canFire to -1 so that it will wait for default amount of time before it can shoot another laser.

Here set the powerupdetected variable to true only when the laser is moving down else the laser may destroy power-up even when it detects player behind it and shoots upwards. It is done inside of Laser script.

Finally destroy the power-up and itself when the power-up enters the collider of the laser.




Unity Developer

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

Recommended from Medium

Scala — Beau[T]y of Type classes

Happenings when ls -l *.c is typed in a shell

Building a Smoke Test Suite in Espresso for Native Android Apps

Scrap frontend rich websites

My #ibelieveindoing journey with Crio.Do

Why Scala?

New Content: Selenium WebDriver with Java

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
Niraj Karki

Niraj Karki

Unity Developer

More from Medium

A guide to setting up a cross platform input controller using the Unity Input System

How to Win the Race Using Director

Cinematography in Unity — Dolly Tracks

Switch Statements To The Rescue!