2D Galaxy Shooter P2: Enemies can Shoot Powerups!

For today’s challenge, I implemented the ability for enemies to shoot power-ups in front of them!

Heyyyy! Why did you do that for? Let me at you!

It was a simple implementation. All I needed to do in the PowerUp script was add a check for enemy projectiles in the OnEnterTrigger2D() function.

if (other.gameObject.CompareTag(“Enemy Projectile”))
{
Projectile[] projectiles = other.GetComponents<Projectile>();
for (int i = 0; i < projectiles.Length; i++)
{
if (projectiles[i].GetIsEnemyLaser() == true)
{
Destroy(projectiles[i].gameObject);
Instantiate(_explosionPrefab, transform.position, Quaternion.identity);
_audioManager.PlayExplosionSound();
Destroy(gameObject, 0.2f);
}
}
}

I also had to make sure the enemy projectile prefabs had the tag “Enemy Projectile” selected.

That was all! Every time an enemy is in front of a power-up and shoots, it will get destroyed. Easy peasy!

That is all for today! Thank you for your time!

Gabriel

--

--

--

Hello everyone, My name is Gabriel Perez, I am a Unity Developer and a creator who is always learning and experimenting.

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

Recommended from Medium

How to start coding with Python

Getting Started with AWS for Unity

🔥 #pSTAKE #TreasureHunt #Community

AWS in Unity Part 3

Kotlin Coroutines MVVM Retrofit UnitTestCases — Part2

2 Days Workshop on Google Cloud Platform.

Understanding Pointers in C

Finding Flow as a Developer 👩‍💻👨‍💻

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
Gabriel Perez

Gabriel Perez

Hello everyone, My name is Gabriel Perez, I am a Unity Developer and a creator who is always learning and experimenting.

More from Medium

2.5D Cert Req: Upgrading to URP

Adding enemies to our greybox Prototype

What are Unity Skyboxes?

Switching Cameras Based on Animation States in Cinemachine