aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcinzelent <zelent.marcin@gmail.com>2019-04-27 12:20:18 +0200
committermarcinzelent <zelent.marcin@gmail.com>2019-04-27 12:20:18 +0200
commitb91f71896693ec1525c2a31b42278e32ba901a06 (patch)
tree874e57cf6c3a5edf309c118d7787602a1a8b0f28 /nGJ2019/Assets/Scripts/HealthBar.cs
parentb1a279b551e2127ff9f530b205f2e1590ae51e9f (diff)
parent5b4381a1993c4a67facc2d5d55b1d5c94f284ca7 (diff)
Merge
Diffstat (limited to 'nGJ2019/Assets/Scripts/HealthBar.cs')
-rw-r--r--nGJ2019/Assets/Scripts/HealthBar.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/nGJ2019/Assets/Scripts/HealthBar.cs b/nGJ2019/Assets/Scripts/HealthBar.cs
new file mode 100644
index 0000000..4c30b42
--- /dev/null
+++ b/nGJ2019/Assets/Scripts/HealthBar.cs
@@ -0,0 +1,54 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class HealthBar : MonoBehaviour
+{
+ public GameObject crystalPrefab;
+ public Material liveCrystal;
+ public Material deadCrystal;
+
+ public int lives;
+
+ private int currentHealth;
+ public int health
+ {
+ get{return currentHealth;}
+ set
+ {
+ currentHealth = value;
+ updateCrystals();
+ }
+ }
+
+ private List<Renderer> crystals = new List<Renderer>();
+
+ private void updateCrystals()
+ {
+ for(int i=0; i<lives; i++)
+ {
+ if(health > i)
+ crystals[i].material = liveCrystal;
+ else
+ crystals[i].material = deadCrystal;
+ }
+ }
+
+ void Start()
+ {
+ for(int i=0; i<lives; i++)
+ {
+ GameObject crystal = Instantiate(crystalPrefab, transform.position + Vector3.right*0.5f*i, Quaternion.identity);
+ crystals.Add(crystal.GetComponentInChildren<Renderer>());
+ }
+
+ health = lives;
+ updateCrystals();
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+
+ }
+}