Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- public class PlayerLives : MonoBehaviour {
- public Image heartPrefab;
- Image newHeart;
- public Transform canvas;
- public List<Image> imgs = new List<Image>();
- RectTransform rT;
- public static bool loseLife = false;
- void Start ()
- {
- DrawHearts();
- }
- void Update()
- {
- if(loseLife)
- {
- if(imgs.Count > 0)
- {
- imgs.RemoveAt(imgs.Count - 1);
- if (canvas.childCount != 0)
- {
- if (canvas.GetChild(3).GetComponent<Image>())
- {
- Destroy(canvas.GetChild(canvas.childCount - 1).gameObject);
- }
- }
- loseLife = false;
- }
- }
- }
- public void DrawHearts()
- {
- for (int i = 0; i < MainGlobals.lives; i++)
- {
- newHeart = Instantiate(heartPrefab) as Image;
- newHeart.transform.SetParent(canvas, false);
- newHeart.rectTransform.anchoredPosition = new Vector2(-20 - (i * 25), -20);
- imgs.Add(newHeart);
- }
- }
- }
Add Comment
Please, Sign In to add comment