Lose Player Health Script

As some of you know that i'm creating a split screen game and can you please help me with the health script I want a health script so as every time my player gets hit it will lose on part of its body thanks

if you are looking for people to do the work for you please post in collaboration and ask for someone to join your project. if you are trying to develop something yourself and get stuck, post a specific question about where you went astray. not to be harsh but this post kinda sounds like "hey caring community, start working on my game". that really isn't what this system is for.

1 Answer

1

something like this would be okay

public float health=100; //the health variable.
public float damage=10; //damage amount.
public void hit()
{
health-= damage;
if (health < 0) 
{//do the killing stuff here}
}

then in the smae script or another one you should have collision or trigger events which call the hit method

Maybe make the hit method accept a damage variable. Then you can use it very easily from other object such as someObject.SendMessage("hit", 10);

first of all sendmessage is slow and should be avoided. also most of the times the enamies will become stronger level by level so setting the damage property of a enamy prefab is much more logical than having a big if ... else ... statement in the player script or so to check the level and enamy type for determining the damage amount. always put things somewhere that you need less code and less designer (level designer) work.