Ejemplo n.º 1
0
        private void StartDash()
        {
            if (_moveDirection.magnitude <= 0.1f)
            {
                return;
            }
            if (!_cooldowns.TryAbility(this))
            {
                return;
            }

            _dashCoroutine = StartCoroutine(DashCoroutine());

            OnBlockEvent?.Invoke(actionBlocks);
            OnStartDash?.Invoke();
        }
Ejemplo n.º 2
0
 public void StartDash(float _duration)
 {
     OnStartDash?.Invoke(_duration);
 }
Ejemplo n.º 3
0
    private void FixedUpdate()
    {
#if UNITY_EDITOR
        if (_infinityMode)
        {
            _currentEnergy = _maxEnergy;
            OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
            _currentFuel = _maxFuel;
            OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
        }
#endif
        if (_currentFuel <= 0)
        {
            return;
        }

        if (_currentFuel > 0)
        {
            _fuelConsumed += _fuelPerSecond * Time.fixedDeltaTime;
        }
        if (_fuelConsumed >= 1)
        {
            _fuelConsumed -= 1;
            _currentFuel   = Mathf.Clamp(--_currentFuel, 0, _maxFuel);
            OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
        }

        if (_currentEnergy < _maxEnergy)
        {
            _energyRecharged += _rechargePerSecond * Time.fixedDeltaTime;
        }
        if (_energyRecharged >= 1)
        {
            _energyRecharged -= 1;
            _currentEnergy    = Mathf.Clamp(++_currentEnergy, 0, _maxEnergy);
            OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
        }

        switch (_currentState)
        {
        case KlunkState.Dashing:
            _remainingTimeDash -= Time.fixedDeltaTime;
            if (!_isDashing)
            {
                _isDashing = true;
                //AudioManager.instance.Play("klunk_dash");
            }
            if (_remainingTimeDash <= 0 || _hitWallWhileDash)
            {
                _currentState = KlunkState.None;
                _characterController.IgnoreAirSpeed(false);
                _characterController.Move(Vector2.zero, 0, _jump);
                _characterController.RemoveFreezeConstraint(RigidbodyConstraints.FreezePositionY);
                _frontAttack.gameObject.SetActive(false);
                _hitWallWhileDash = false;
                _frictionController.SetMaxFriction();
                _characterController.IgnoreHorizontalClampedSpeed(false);
                _characterController.IgnoreSpeedSmooth(false);
                _characterController.DontIncrementSpeed(false);
                _isDashing = false;
                OnEndDash?.Invoke(transform.position);
            }
            break;

        case KlunkState.Sk8erBoi:
            if (_currentEnergy <= 0 || !_actionMov2Pressed)
            {
                _currentState = KlunkState.None;
                _characterController.SetBaseSpeedMultiplier(1);
                OnEndSkate?.Invoke(transform.position);
                _isSkating = false;
                //AudioManager.instance.Stop("klunk_skate");
                return;
            }
            if (!_isSkating)
            {
                _isSkating = true;
                //AudioManager.instance.Play("klunk_skate");
            }
            _characterController.Move(_actionMove.ReadValue <Vector2>(), _sk8SpeedFactor, _jump);
            _energyConsumed += _sk8erBoiEnergyCostPerSecond * Time.fixedDeltaTime;
            if (_energyConsumed >= 1)
            {
                _energyConsumed -= 1;
                _currentEnergy   = Mathf.Clamp(--_currentEnergy, 0, _maxEnergy);
                OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
            }
            break;

        default:
            _characterController.Move(_actionMove.ReadValue <Vector2>(), 1, _jump);
            if (!_isWalking)
            {
                _isWalking = true;
                //AudioManager.instance.Play("klunk_walk");
            }
            if (_actionMov1.triggered && _currentEnergy >= _dashEnergyCost)
            {
                _characterController.IgnoreAirSpeed(true);
                if (_characterController.FacedRight)
                {
                    _characterController.Move(Vector2.right, _dashSpeedFactor, _jump);
                }
                else
                {
                    _characterController.Move(-Vector2.right, _dashSpeedFactor, _jump);
                }
                _characterController.AddFreezeConstraint(RigidbodyConstraints.FreezePositionY);
                _frontAttack.gameObject.SetActive(true);
                _remainingTimeDash  = _dashMaxDistance / (_characterController.BaseSpeed * _dashSpeedFactor);
                _remainingTimeDash -= Time.fixedDeltaTime;
                _currentState       = KlunkState.Dashing;
                _currentEnergy      = Mathf.Clamp(_currentEnergy - _dashEnergyCost, 0, _maxEnergy);
                OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
                _frictionController.SetZeroFriction();
                _characterController.IgnoreHorizontalClampedSpeed(true);
                _characterController.IgnoreSpeedSmooth(true);
                _characterController.DontIncrementSpeed(true);
                OnStartDash?.Invoke(transform.position);
                temp_startPosition = transform.position;
                _isWalking         = false;
                //AudioManager.instance.Play("klunk_walk");
                return;
            }
            else if (_actionMov2Pressed && _currentEnergy > _sk8erBoiEnergyCostPerSecond)
            {
                _currentState = KlunkState.Sk8erBoi;
                _characterController.SetBaseSpeedMultiplier(_sk8SpeedFactor);
                OnStartSkate?.Invoke(transform.position);
                _isWalking = false;
                //AudioManager.instance.Play("klunk_walk");
                return;
            }
            break;
        }
    }