private void Win() { _smooch.Play(); _state = GameStates.WIN; _girl.color = _normColor; _stealthState = StealthStates.BUSTED; //just to get the eye movement _OnWin.Invoke(); //score logic if (PlayerPrefs.HasKey("record")) { float hs = PlayerPrefs.GetFloat("record"); if (_gameTimer > hs) { PlayerPrefs.DeleteAll(); PlayerPrefs.SetFloat("record", _gameTimer); StartCoroutine(RecordBlink()); } } else { PlayerPrefs.SetFloat("record", _gameTimer); StartCoroutine(RecordBlink()); } }
private void Move() { transform.localPosition += Vector3.left * _moveSpeed; _curProgress = Mathf.Abs(transform.localPosition.x - _lastKnownPos); float progPercent = Mathf.CeilToInt(Mathf.InverseLerp(_startPos, _winPos, transform.localPosition.x) * 100f); _progText.text = progPercent.ToString("#") + "%"; //sus logic if (Random.value * _curProgress > _susRange) { _stealthState = StealthStates.SUSPECT; _girl.color = _susColor; _susTimer = 0; _lastKnownPos = transform.localPosition.x; _susTime = Random.Range(_minSus, _maxSus); _alert.Play(); } //win logic if (transform.localPosition.x <= _winPos) { Win(); } _scooch.pitch = Random.Range(_scoochAudioRange.x, _scoochAudioRange.y); _scooch.Play(); }
// Update is called once per frame void Update() { switch (_state) { case GameStates.INTRO: if (Time.timeSinceLevelLoad > _introTime) { _state = GameStates.PLAY; } break; case GameStates.PLAY: _moved = false; _gameTimer += Time.deltaTime; _curTime.text = "Current time: " + _gameTimer.ToString("#.##"); if (Input.anyKeyDown) { Move(); _moved = true; } break; case GameStates.WIN: break; default: break; } switch (_stealthState) { case StealthStates.CHILL: _eyes.localPosition = Vector3.right * Mathf.Lerp(_eyes.localPosition.x, _normEyePos, _eyeSpeed * Time.deltaTime); break; case StealthStates.SUSPECT: _eyes.localPosition = Vector3.right * Mathf.Lerp(_eyes.localPosition.x, _susEyePos, _eyeSpeed * Time.deltaTime); _susTimer += Time.deltaTime; _girl.color = Color.Lerp(_susColor, _normColor, _susTimer / _susTime); if (_susTimer > _gracePeriod && _moved) { Lose(); } if (_susTimer > _susTime) { _girl.color = _normColor; _stealthState = StealthStates.CHILL; _chill.Play(); } break; case StealthStates.BUSTED: _eyes.localPosition = Vector3.right * Mathf.Lerp(_eyes.localPosition.x, _bustedEyePos, _eyeSpeed * Time.deltaTime); break; default: break; } }
private void Lose() { _busted.Play(); _girl.color = _bustedColor; _stealthState = StealthStates.BUSTED; _state = GameStates.LOSE; _OnLose.Invoke(); }