Simple Sample Project that contain a 3D Life Bar that can decrease or increase dpending what you need.
3D Life Bar Sample Project
This is a basic sample project designed to demonstrate how to create and use a 3D life bar in a game.
Overview
The project showcases a 3D life bar modeled in Blender and implemented as a simple rectangular cube. The life bar visually indicates an entity's health by dynamically scaling down its z-axis as health decreases. In this sample, tapping on the screen throws projectiles at an enemy, reducing its health and updating the life bar accordingly.
How It Works
3D Life Bar:
The life bar is represented as a rectangular cube. As the enemy takes damage, the cube's z-axis scale is reduced proportionally to reflect the current health status.User Interaction:
The project uses a tap event to trigger the shooting of projectiles. Each tap throws a projectile at the enemy, which in turn decreases the enemy's health and updates the life bar.Customization:
While this sample uses the tap input, you can easily modify it to use any custom events that suit your project's needs.
Features
- Dynamic 3D Life Bar:
A life bar that visually decreases in size based on the entity's remaining health.- Customization Tip: You can easily change the color of your life bar.
- Very Important:
Change the life bar pivot point to the front this is essential for the logic to work correctly. - Life Bar Frame:
There is also a 3D object in case you want to add a frame to your life bar. The color of this frame can also be easily customized.
Scripts Overview
This project includes three main scripts:
lifeBarManager.ts
Manages the health of the entity by detecting collisions and decreasing health. It also handles enemy state, if the enemy is dead, health removal stops and the life resets after 2 seconds.projectile.ts
Handles the throwing of projectiles in the direction of the enemy.entity-role.ts
Helps set up entities that have colliders by assigning a role to them. This is used by to assign a role to the projectile (ball) when it's created and by to verify that a collision occurred with a projectile that contain role projectile.