Commit b338a08d authored by Unknown's avatar Unknown
Browse files

Adding HeartMeter UI script, sprites and scene

parent 1f2054be
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class HeartManager : MonoBehaviour {
public Image leftheart;
public Image rightheart;
public int currenthealth;
private int lasthealth;
public Sprite[] heartSprites;
void Start()
{
currenthealth = 8;
lasthealth = currenthealth;
checkHealth();
updateheart(currenthealth);
}
void Update()
{
if (lasthealth != currenthealth)
updateheart(currenthealth);
lasthealth = currenthealth;
}
void checkHealth()
{
leftheart.enabled = true;
rightheart.enabled = true;
}
void updateheart(int health)
{
if (currenthealth > 4)
{
leftheart.sprite = heartSprites[4];
if (currenthealth == 8)
rightheart.sprite = heartSprites[4];
else if (currenthealth == 7)
rightheart.sprite = heartSprites[3];
else if (currenthealth == 6)
rightheart.sprite = heartSprites[2];
else if (currenthealth == 5)
rightheart.sprite = heartSprites[1];
}
else
{
rightheart.sprite = heartSprites[0];
if (currenthealth == 4)
leftheart.sprite = heartSprites[4];
else if (currenthealth == 3)
leftheart.sprite = heartSprites[3];
else if (currenthealth == 2)
leftheart.sprite = heartSprites[2];
else if (currenthealth == 1)
leftheart.sprite = heartSprites[1];
else if (currenthealth == 0)
leftheart.sprite = heartSprites[0];
}
}
}
fileFormatVersion: 2
guid: 3fd9c01e8800fc54681146f720a0d04b
folderAsset: yes
timeCreated: 1477008945
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment