void BindToHandlers() { HeroCharacter.GetInstance().HeroStateHandler.onTakeDamageCallBack += UpdateHealth; HeroCharacter.GetInstance().HeroStateHandler.onTakeDamageCallBack += DamageCameraShake; HeroCharacter.GetInstance().HeroStateHandler.onHealingCallBack += UpdateHealth; InputHandler.MenuController.onPause += ShowPause; }
private IEnumerator DamageImunity() { isImune = true; yield return(new WaitForSeconds(HeroCharacter.GetInstance().ImunityDuration)); isImune = false; }
private void Start() { mRenderers = GetComponentsInChildren <MeshRenderer>(); foreach (var mrender in mRenderers) { mrender.material = Instantiate(mrender.material) as Material; } HeroCharacter.GetInstance().HeroStateHandler.onHitImunityCallback += Blink; }
private void DamageCameraShake() { SpringArm.GetInstance().DoShakeCamera(0.5f, 0.1f); float intensity = (HeroCharacter.GetInstance().CurrentHealth % 3 == 0) ? 1f : 0.3f; //If the heart piece is the last in the container(3 pieces), //then the screen flashes with more intensity DoFlashOverlay(1f, intensity); }
public override void DamageCharacter(float damage) { if (isImune) { return; } base.DamageCharacter(damage); if (onHitImunityCallback != null) { onHitImunityCallback(HeroCharacter.GetInstance().ImunityDuration); StartCoroutine(DamageImunity()); } }
private void UpdateHealth() { int currentHealth = HeroCharacter.GetInstance().CurrentHealth; //This approach makes sure that it will work for any amount of damage or heal for (int i = 0; i < heartPieces.Count; i++) { //If the heart piece index is smaller than the current amount of heart pieces the player has, AND it is disabled, then activate it (heal) if (i < currentHealth && !heartPieces[i].activeSelf) { heartPieces[i].SetActive(true); } //If the heart piece index is bigger than the current amount of heart pieces the player has, AND it is activated, then deactivate it (damage) else if (i >= currentHealth && heartPieces[i].activeSelf) { heartPieces[i].SetActive(false); //spawn particle system and position it at the heart piece location GameObject clone = PoolManager.Spawn <UIDamage>().gameObject; if (clone == null) { return; } clone.transform.position = heartPieces[i].transform.position; clone.transform.LookAt(Camera.main.transform.position); } } int currentHeart = HeroCharacter.GetInstance().CurrentHeartContainerIndex; //Makes the current heart container bigger then the others for (int i = 0; i < uiControl.heartContainers.Length; i++) { if (i == currentHeart) { uiControl.heartContainers[i].transform.localScale = Vector3.one; } else { uiControl.heartContainers[i].transform.localScale = Vector3.one * 0.8f; } } }
void InitHeartContainers() { int heartContainerCount = HeroCharacter.GetInstance().MaxHeartPieceCount; heartPieces = new List <GameObject>(); //activate heart containers based on how many are defined to be available to the player //this number can change at design time, and run time by picking up upgrades for (int i = 0; i < heartContainerCount; i++) { uiControl.heartContainers[i].SetActive(true); //Track how many heart pieces the player has foreach (Transform item in uiControl.heartContainers[i].transform) { heartPieces.Add(item.gameObject); } //Make the last healthy heart container bigger if (i == heartContainerCount - 1) { uiControl.heartContainers[i].transform.localScale = Vector3.one; } } }
private void Start() { InputHandler.MenuController.onPause += PlayPause; HeroCharacter.GetInstance().HeroStateHandler.onHealingCallBack += PlayHealing; HeroCharacter.GetInstance().HeroStateHandler.onTakeDamageCallBack += PlayGettingHit; }