init
This commit is contained in:
commit
16da8e4dde
333 changed files with 109229 additions and 0 deletions
39
Assets/Scripts/HealthBar.cs
Normal file
39
Assets/Scripts/HealthBar.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HealthBar : MonoBehaviour{
|
||||
|
||||
public int maxHp;
|
||||
[HideInInspector] public float hp;
|
||||
public Image healthBar;
|
||||
public Image timer;
|
||||
[HideInInspector] public float time;
|
||||
GameController gameController;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
hp = maxHp;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (gameController.ready){
|
||||
timer.transform.localScale = new Vector2(time, timer.transform.localScale.y);
|
||||
time = Mathf.Clamp(time + Time.deltaTime / 30, 0f, 1f);
|
||||
}else{
|
||||
timer.transform.localScale = new Vector2(0, timer.transform.localScale.y);
|
||||
}
|
||||
}
|
||||
|
||||
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