private IEnumerator Exhale() { while (Status.fillAmount > 0f && Math.Abs(Cameras[0].orthographicSize - _originalCameraSize) > 0.0000001f) { Status.fillAmount -= 0.01f; Status.color = Color.Lerp(_from, Color.green, 1f - Status.fillAmount); if (_penalty > 10f) { PlayerBehaviour.CurrentPlayer.Noise = Status.fillAmount; } for (int i = 0; i < Cameras.Length; i++) { Cameras[i].orthographicSize = Mathf.SmoothDamp(Cameras[i].orthographicSize, _originalCameraSize, ref _velocity, 0.3f); } yield return(new WaitForEndOfFrame()); } if (_penalty <= 0f) { _source.Stop(); } _state = EInhaleStatus.None; Status.gameObject.SetActive(false); }
public void OnPointerUp(PointerEventData eventData) { _state = EInhaleStatus.Exhaling; _inhaled = false; AudioSource.PlayClipAtPoint(ExhaleSound, Camera.main.transform.position, Status.fillAmount); PlayerBehaviour.CurrentPlayer.Noise = Status.fillAmount / 2f; PlayerQuirks.StoppedBreathing = false; if (_shouldCancelPenalty) { _penalty = _timePassed * 0.3f; PenaltyTime = _timePassed * 0.3f; } }
public void OnPointerDown(PointerEventData eventData) { if (_state == EInhaleStatus.None && _penalty <= 0f) { _source.Play(); _shouldCancelPenalty = true; AudioSource.PlayClipAtPoint(InhaleSound, Camera.main.transform.position, 0.2f); Debug.Log("Camera size" + _originalCameraSize); PlayerQuirks.StoppedBreathing = true; _state = EInhaleStatus.Inhaled; StopAllCoroutines(); Status.gameObject.SetActive(true); _timePassed = 0f; } }
void Update() { HandlePenaltyIfNeeded(); switch (_state) { case EInhaleStatus.Inhaled: { _timePassed += Time.unscaledDeltaTime; if (_timePassed <= MaxInhaleTime) { Status.fillAmount = _timePassed / MaxInhaleTime; _source.volume = _timePassed / MaxInhaleTime; for (int i = 0; i < Cameras.Length; i++) { Cameras[i].orthographicSize = Mathf.SmoothDamp(Cameras[i].orthographicSize, _originalCameraSize * 0.5f, ref _velocity, MaxInhaleTime); } Status.color = Color.Lerp(Color.green, Color.red, Status.fillAmount); } else { _state = EInhaleStatus.Exhaling; PenaltyTime = GaspSound.length; _penalty = PenaltyTime; _shouldCancelPenalty = false; AudioSource.PlayClipAtPoint(GaspSound, Camera.main.transform.position, 1f); } break; } case EInhaleStatus.Exhaling: { _from = Status.color; PlayerQuirks.StoppedBreathing = false; _state = EInhaleStatus.Exhaled; StartCoroutine(Exhale()); break; } } }