-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHealthBar.cs
33 lines (28 loc) · 842 Bytes
/
HealthBar.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using UnityEngine;
using System.Collections;
public class HealthBar : MonoBehaviour {
//public float repeatDamagePeriod=2f;
//public AudioClip[] ouchSounds;
//public float hurtForce=10f;
//public float damageAmount=10f;
SpriteRenderer healthBar;
//private float lastHitTime;
private Vector3 healthScale;
private Player player;
void Start ()
{
healthBar=transform.GetComponent<SpriteRenderer>();
healthScale=healthBar.transform.localScale;
player=GameObject.Find ("Player").GetComponent<Player>();
}
void Update()
{
if(player.health>=0)
UpdateHealthBar();
}
public void UpdateHealthBar()
{
healthBar.material.color=Color.Lerp (Color.green,Color.red,1-player.health*0.01f);
healthBar.transform.localScale=new Vector3(healthScale.x*player.health*0.01f,transform.localScale.y,transform.localScale.z);
}
}