Pong-Pong/Assets/Scripts/Player/PlayerHealth.cs
Gerard Gascón 16da8e4dde init
2025-04-24 17:09:22 +02:00

25 lines
673 B
C#

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);
}
}
}