We’ve been Hit! How to Visualize Player Damage in Unity

In the past day I’ve added a rotating Asteroid that when hit will start the enemy spawn routine. I’ve also added a thruster animation to the Player ship. It looks really cool. Nothing too new in doing so. Just a lot of the same animation patterns we’ve used previously.

In the name of emersion I thought it would be cool to add a visual representation when the player takes a hit by adding a fireball with a smoke trail.

I start by dragging the first sprite image from the animation into the hierarchy. As we’ve done before I created an animation from it. I and then dragged it into the scene view. ( I made a prefab of each) As a child of the Player Object. I then duplicated it and renamed it Right_Damange and Left Damage respectively.

From the inspector for each I then make sure that they are turned off by default. Now comes the fun part. How do I want this behavior to work and where should I turn it on?

Easy! So everytime I take a hit I need to activate the appropriate Animation. This happens in the public void Damage() method. This is what my implementation looks like.

And finally here’s what it looks like in engine. Check back tomorrow when I’ll be discussing the topic of post processing in Unity.




Unity Developer — Technology Leader — Making Unity Game Development Look Easy

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

Recommended from Medium

A Hacker’s Guide to Competitive Programming

The Python Story

AWS Lambda function with DynamoDB and API Gateway

Embed code not available

Android MAN Wallet For Test

Run your startup BETTER, not FASTER!

How do I set up my local Kubernetes environment today? — Part 2

MANTA GitHub (5)

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
Games Woods

Games Woods

Unity Developer — Technology Leader — Making Unity Game Development Look Easy

More from Medium

My journey becoming a Unity game developer: 2.5D Infinite Runner-Ledge Grab System-Pt3

Benefits of Prototyping with Cubes

Week 24: How to add SFX to you game without going mad

Player 1 Is Ready To Move Around