예제 #1
0
    private void EnergyBehaviour()
    {
        if (_playerEnergy != null && canBeConsumed)
        {
            float   distance  = Vector3.Distance(_playerEnergy.transform.position, transform.position);
            Vector2 direction = _playerEnergy.transform.position - transform.position;

            if (distance <= _distanceReference)
            {
                _rb.velocity       = direction.normalized * _currentMoveSpeed * Time.deltaTime;
                _currentMoveSpeed += _moveSpeedIncrease;
            }
            else
            {
                _rb.velocity      = new Vector2(0, 0);
                _currentMoveSpeed = _startingMoveSpeed;
            }

            if (distance <= _distanceToMove)
            {
                _playerEnergy.AddEnergy(_energyToAdd);
                _uiManager.UpdateEnergySlider();
                _playerEnergyPoints.AddRemovePoints(_energyPointsValue);
                Destroy(gameObject);
            }
        }
    }
    public void PlayerSpeedUpgrade(float amount, int cost)
    {
        if (_playerEnergyPoints.energyPoints >= cost && _currentSpeedUpgrade < _maxSpeedUpgrade)
        {
            _playerEnergyPoints.AddRemovePoints(-cost);
            _playerController.defaultMovementSpeed += amount;
            _playerController.currentMovementSpeed  = _playerController.defaultMovementSpeed;

            SpeedUpgradeAmount += SpeedUpgradeAmount * _upgradeValueMultiplier;
            int newSpeedUpgradeCost = Mathf.RoundToInt(SpeedUpgradeCost * _upgradeCostMultiplier);
            SpeedUpgradeCost += newSpeedUpgradeCost;

            _currentSpeedUpgrade++;
            print("Upgrade complete");

            SpeedUpgradesLeft = _maxSpeedUpgrade - _currentSpeedUpgrade;
            _uiManager.UpdateUpgradesCount(SpeedUpgradesLeft, _uiManager.speedUpgradesLeft);
        }
        else
        {
            print("max upgrades reached");
        }
    }