init
This commit is contained in:
commit
16da8e4dde
333 changed files with 109229 additions and 0 deletions
25
Assets/Scripts/Player/PlayerHealth.cs
Normal file
25
Assets/Scripts/Player/PlayerHealth.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerHealth : MonoBehaviour{
|
||||
|
||||
public int maxHp;
|
||||
[HideInInspector]
|
||||
public float hp;
|
||||
public GameObject healthBar;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
hp = maxHp;
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage){
|
||||
hp -= damage;
|
||||
if (hp > 0 && hp > damage){
|
||||
healthBar.transform.localScale = new Vector2(hp / maxHp, healthBar.transform.localScale.y);
|
||||
}else if (hp < damage){
|
||||
healthBar.transform.localScale = new Vector2(0, healthBar.transform.localScale.y);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue