diff options
Diffstat (limited to 'Assets/Scripts')
-rw-r--r-- | Assets/Scripts/Actors/Actor.cs | 6 | ||||
-rw-r--r-- | Assets/Scripts/UI.cs | 43 | ||||
-rw-r--r-- | Assets/Scripts/UI.cs.meta | 11 |
3 files changed, 57 insertions, 3 deletions
diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs index 55aed29..63854d9 100644 --- a/Assets/Scripts/Actors/Actor.cs +++ b/Assets/Scripts/Actors/Actor.cs @@ -26,11 +26,11 @@ namespace MontanaJohns.Actors protected bool isGrappling; protected Vector2? grapplePoint = null; protected LayerMask groundLayers; - Collection<Item> items; - - protected int health; + protected Collection<Item> items; protected int jumpCount; protected Vector2 acceleration; + + public int health; protected virtual void Awake() { diff --git a/Assets/Scripts/UI.cs b/Assets/Scripts/UI.cs new file mode 100644 index 0000000..0c0802e --- /dev/null +++ b/Assets/Scripts/UI.cs @@ -0,0 +1,43 @@ +using MontanaJohns.Actors; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class UI : MonoBehaviour +{ + [SerializeField] private int heartCount; + [SerializeField] private Image[] hearts; + [SerializeField] private Sprite heartSprite; + + public int health; + + private void Start() + { + for (int i = 0; i < hearts.Length; i++) + { + if (i < heartCount) + hearts[i].enabled = true; + else + hearts[i].enabled = false; + } + } + + private void Update() + { + health = gameObject.GetComponent<Actor>().health; + for(int i = 0; i < heartCount; i++) + { + /* Can be used to have two sprites, one empty/one full/half full, etc. + if (i < health) + hearts[i].sprite = heartSprite; + else + hearts[i].sprite = heartSprite2; + */ + if (i < health) + hearts[i].enabled = true; + else + hearts[i].enabled = false; + } + } +} diff --git a/Assets/Scripts/UI.cs.meta b/Assets/Scripts/UI.cs.meta new file mode 100644 index 0000000..6dadbf3 --- /dev/null +++ b/Assets/Scripts/UI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e59148c42c36f95438441511c27f1728 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |