private IEnumerator PopulateHearts() { hearts = new List <HeartUI>(); numHearts = playerHealth; int i = 0; for (i = 0; i < numHearts; i++) { HeartUI go = Instantiate(heartUIPrefab, transform).GetComponent <HeartUI>(); if (go) { hearts.Add(go); go.Init(); } } for (i = 0; i < hearts.Count; i++) { waitingOnSpawn = true; hearts[i].StartAnimation(this); while (waitingOnSpawn) { yield return(null); } } UpdateHearts(playerHealth); }
private void UpdateUI() { int heartsToRender = hp.MaxHP; int currentHp = hp.CurrentHP; bool isRegen = !hp.IsInCombatMode(); for (int i = 0; i < hearts.Count; i++) { HeartUI heartUI = hearts[i]; if (i < heartsToRender) { heartUI.Show(); if (i < currentHp) { heartUI.PlayFull(); } else if (isRegen) { heartUI.PlayRegen(); } else { heartUI.PlayEmpty(); } } else { heartUI.Hide(); } } renderedCurrentHP = currentHp; renderedMaxHP = heartsToRender; }
private void OnSceneLoaded(Scene arg0, LoadSceneMode arg1) { var player = GameObject.FindGameObjectWithTag("Player"); healthUi = player.GetComponentInChildren <HeartUI>(); healthUi.UpdateHearts(); var memoryGO = GameObject.FindGameObjectWithTag("memory"); var memory = memoryGO.GetComponent <transitionMemory>(); memory.fadeOut = true; var spawName = memory.nextDoor; var door = GameObject.Find(spawName); if (spawName == "HubTeleport") { var go = GameObject.Find(spawName); transform.position = go.transform.position + Vector3.up * GetComponent <CapsuleCollider>().height / 2; healthSO.health = healthSO.maxHealth; healthUi.UpdateHearts(); return; } var spawnTransform = door.transform.GetChild(0); print(spawnTransform.position); transform.position = spawnTransform.transform.position + Vector3.up * GetComponent <CapsuleCollider>().height / 2; }
void removeHeart() { GameObject heart = hearts.Pop(); HeartUI heartUI = heart.GetComponent <HeartUI> (); heartUI.blinkAndDie(); }
private void UpdateUIAfterDamage() { int currentHp = hp.CurrentHP; int maxHp = hp.MaxHP; int hpLost = renderedCurrentHP - currentHp; for (int i = 0; i < hpLost; i++) { int heartIndex = renderedCurrentHP - i - 1; HeartUI heartUI = hearts[heartIndex]; heartUI.PlayLost(); } int emptyHearts = renderedMaxHP - renderedCurrentHP; for (int i = 0; i < emptyHearts; i++) { int heartIndex = renderedMaxHP - i - 1; HeartUI heartUI = hearts[heartIndex]; heartUI.PlayEmpty(); } renderedCurrentHP = currentHp; renderedMaxHP = maxHp; }
void Start() { GetComponent <BoxCollider2D>().isTrigger = true; _HeartUI = FindObjectOfType <HeartUI>(); }