private void Awake() { _magnetic = GetComponent <Magnetic>(); _currentState = RoyStates.None; _currentEnergy = _maxEnergy; OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy); _currentFuel = _maxFuel; OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel); _energyPerSecond = (float)_maxEnergy / _energyTimeDuration; _rechargePerSecond = (float)_maxFuel / _totalTimeToReloadFullFuel; _aimController = GetComponentInChildren <AimController>(); var playerInputComponent = GetComponent <PlayerInput>(); _magnetic.OnPull += _onPlayerPull_Magnetic; _actionMove = playerInputComponent.actions["Move"]; _actionJump = playerInputComponent.actions["Jump"]; _actionJump.performed += _actionJump_performed; _actionJump.canceled += _actionJump_canceled; _actionMov1 = playerInputComponent.actions["Mov1"]; _actionMov1.started += _actionMov1_started; _actionMov1.canceled += _actionMov1_canceled; _actionMov2 = playerInputComponent.actions["Mov2"]; _actionMov2.performed += _actionMov2_performed; _actionMov2.canceled += _actionMov2_canceled; _animator.Play("Roy_Armature_Idle"); }
private void FixedUpdate() { #if UNITY_EDITOR if (_infinityMode) { _currentEnergy = _maxEnergy; OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy); _currentFuel = _maxFuel; OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel); } #endif if (_currentEnergy <= 0) { return; } if (_currentEnergy > 0) { _energyConsumed += _energyPerSecond * Time.fixedDeltaTime; } if (_energyConsumed >= 1) { _energyConsumed -= 1; _currentEnergy = Mathf.Clamp(--_currentEnergy, 0, _maxEnergy); OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy); } if (_currentFuel < _maxFuel) { _fuelRecharged += _rechargePerSecond * Time.fixedDeltaTime; } if (_fuelRecharged >= 1) { _fuelRecharged -= 1; _currentFuel = Mathf.Clamp(++_currentFuel, 0, _maxFuel); OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel); OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel); } switch (_currentState) { case RoyStates.Hooked: if (_currentFuel <= 0 || !_actionMovHookPressed) { _currentState = RoyStates.None; UnHook(); _characterController.SetHook(false); return; } _fuelConsumed += _hookFuelCostPerSecond * Time.fixedDeltaTime; if (_fuelConsumed >= 1) { _fuelConsumed -= 1; _currentFuel = Mathf.Clamp(--_currentFuel, 0, _maxFuel); OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel); } _characterController.Move(_actionMove.ReadValue <Vector2>(), 1, false); break; case RoyStates.Boosting: if (!_isHovering) { _isHovering = true; //AudioManager.instance.Play("roy_hover"); } if (_currentFuel <= 0 || !_actionMovBoostPressed) { _currentState = RoyStates.None; //AudioManager.instance.Stop("roy_hover"); _isHovering = false; } _fuelConsumed += _boostCostPerSecond * Time.fixedDeltaTime; if (_fuelConsumed >= 1) { _fuelConsumed -= 1; _currentFuel = Mathf.Clamp(--_currentFuel, 0, _maxFuel); OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel); } break; default: if (!_isWalking) { _isWalking = true; //AudioManager.instance.Play("roy_walk"); } _characterController.Move(_actionMove.ReadValue <Vector2>(), 1f, _jump); if (_actionMovHookPressed && _currentFuel >= _hookFuelCostPerSecond && HasHookPoint()) { _characterController.SetHook(true); _currentState = RoyStates.Hooked; //AudioManager.instance.Stop("roy_walk"); _isWalking = false; HookTo(_aimHitInfo.point); return; } if (_actionMovBoostPressed && _currentFuel >= _boostCostPerSecond) { _currentState = RoyStates.Boosting; //AudioManager.instance.Stop("roy_walk"); _isWalking = false; return; } break; } }