Animator blinkingAnimator; // The animator which controlls the eye lids #endregion void Awake() { oxygenBar = GameObject.FindWithTag("OxygenBar").GetComponent <Slider>(); // If the level uses the lungs set up for the lungs if (lungsActive) { lungs = GameObject.FindWithTag("Lungs"); lungState = LungState.EMPTY; lungCapacity = 0f; lungCapacityBar = GameObject.FindWithTag("LungCapacityBar").GetComponent <Slider>(); Image[] images = lungCapacityBar.GetComponentsInChildren <Image>(); foreach (Image i in images) { if (i.name == "Fill") { lungCapacityBarFill = i; } else if (i.name == "Handle") { lungCapacityBarHandle = i; } } } }
/// <summary> /// This function updates the lungState based on which key is pressed. /// </summary> void UpdateLungState() { switch (lungState) { case LungState.EMPTY: // If the lungs are empty if (Input.GetKeyDown(inhaleKey)) // The lungs will begin to inhal when you press the inhale key { lungState = LungState.INHALING; BreathingSoundController.instance.StartInhaling(); } break; case LungState.INHALING: // If the lungs are inhaling oxygenLossTimer = 0f; lungCapacity += inhaleSpeed * Time.deltaTime; // Lung capacity increases at a constant rate while inhaling oxygen += oxygenGainSpeed * Time.deltaTime * inefficiencyMulti; // While the lungs are inhaling the oxygen level also increases if (Input.GetKey(inhaleKey) == false || lungCapacity >= 1f) // If the player releases the inhale key or the max lung capacity is reached the lungs begin to hold { lungState = LungState.HOLDING; BreathingSoundController.instance.StopInhaling(); } if (Input.GetKeyDown(exhaleKey)) // If you press the exhale key while still inhaling you will start exhaling { lungState = LungState.EXHALING; BreathingSoundController.instance.StartExhaling(); } break; case LungState.HOLDING: // If the lungs are holding if (Input.GetKeyDown(exhaleKey)) // Pressing the exhale key will begin to exhale { lungState = LungState.EXHALING; BreathingSoundController.instance.StartExhaling(); } break; case LungState.EXHALING: // If the lungs are exhaling if (Input.GetKey(exhaleKey)) // The lungs exhale at a constant rate as long as you continue to hold the exhale key { lungCapacity -= exhaleSpeed * Time.deltaTime; BreathingSoundController.instance.ResumeExhaling(); } else { BreathingSoundController.instance.PauseExhaling(); } if (lungCapacity <= Mathf.Epsilon) // If the lungs capcity reaches 0 then the lungs are empty { lungState = LungState.EMPTY; BreathingSoundController.instance.PauseExhaling(); } break; } }