private void OnLivesChanged(int lives, int max) { // If player gets more health during playtime, // add more hearts if (max > hearts.Count) { UIPaddle paddle = AddPaddle(); paddle.isFull = true; } // If player loses hearts during playtime, // remove hearts if (max < hearts.Count) { int remove = hearts.Count - max; hearts.RemoveRange(max, remove); for (int i = 0; i < remove; ++i) { Destroy(transform.GetChild(max)); } } for (int i = 0; i < max; ++i) { hearts[i].isFull = i < lives; } }
private UIPaddle AddPaddle() { GameObject instance = Instantiate(paddlePrefab); instance.transform.SetParent(transform, false); UIPaddle paddle = instance.GetComponent <UIPaddle>(); hearts.Add(paddle); return(paddle); }
private void Awake() { health.onLivesChanged += OnLivesChanged; hearts = new List <UIPaddle>(health.maxLives); for (int i = 0; i < health.maxLives; ++i) { UIPaddle paddle = AddPaddle(); paddle.isFull = false; } }