system
1
I’m trying to make a player spawn at lv 1 (beginning of game) then save the data later. But when the player spawns, its hp remains 0, which means the script has to destroy the player. How do I start with full hp? Heres my script:
function Update ()
{
if(level==0)
{
level+=1;
}
hp = Mathf.RoundToInt((((ivhp+(2*basehp)+(evhp/4)+100)*level)/100)+10);
currenthp = hp;
system
2
var levelHPModifier:float;
function Awake(){
hp=10+levelHPModifier*level //or whatever your algorithm is
currenthp=hp
}
var ApplyDamage(damage:int){
currenthp-=damage;
//Code for visuals and other stuff goes here
}
var levelUp(){
hp+=levelHPModifier*level
currenthp+=levelHPModifier*level
}
I am going to assume hp is the maximum hp and currenthp is the character’s hitpoints at any given time.
That is pretty much everything you need to make it functional , without setting the hp every frame.
Setting the hp to a certain number every frame may lead to the player ignoring getting damage , since his health is set to a number every frame.
The function Awake sets the player’s ax hp and current hp depending on his level , right when the map is loaded , so your character will not start with 0hp.
The rest of the functions are for generic usage , you can use ApplyDamage with a positive number to do damage , or with a negative to heal your player.
Level up increases the maximum hp for the character , and adds the amount of maximum hp added to the player.