Health Script
July 3, 2024
Entry: 13.0
As I said yesterday that I would make a healthscript, so here I am. I started off with the booleans isdead, ishit and isenemy. I then created maxhealth, armor, minhealth and currenthelth floats. I made sure that in the stat method, the currenthealth is equal to maxhealth. I then made sure that if health was less than or equal to minhealth, isdead was set to true. To finish, I created a takedamage() function, that tool 2 parameters; damage (float) and isprrmorpeircing (boolean). It simply does this equation if isprrmorpeircing is false: currenthealth -= (damage - armor); And this equation if isprrmorpeircing is true: currenthealth -= damage; Feel free to copy this code and use it in your own projects. And if you have any, please give me ways to make the script better.
public bool IsEnemy = false;
public bool IsDead = false;
public float CurrentHealth = 100.0f;
public float MaxHealth = 100.0f;
public float minHealth = 0.0f;
public float armor = 0;
[HideInInspector]
public bool IsHit = false;
// Start is called before the first frame update
void Start()
{
CurrentHealth = MaxHealth;
}
// Update is called once per frame
void Update()
{
if (CurrentHealth <= minHealth)
{
IsDead = true;
}
}
public void takeDamage(float damage, bool IsArrmorPeircing)
{
if (!IsArrmorPeircing)
{
damage -= armor;
if (damage < 0)
{
CurrentHealth -= damage;
}
}
if (IsArrmorPeircing)
{
CurrentHealth -= damage;
}
}
Please check out my profile.
Bulletstorm
Spy FPS adventure game! Estimated release in mid 2026!
More posts
- Taking A BreakJul 10, 2024
- Last SoundtrackJul 09, 2024
- RoadmapsJul 09, 2024
- SoundtracksJul 08, 2024
- Change Of PlansJul 07, 2024
- Animation Script AdditionJul 06, 2024
- Health BarJul 05, 2024
- Independence Day SpecialJul 04, 2024
- M4A1 animations: Logic and IdleJul 02, 2024
Comments
Log in with itch.io to leave a comment.
Cool!
Thanks! You should use it in your new game, it's easy to expand on.
Look what Larry posted. Did you ask him? I didn't.
I didn’t either. :)
I copied it for my multiplayer. Thanks. ;>)
No problem!