Beispiel #1
0
 public void AddItemToInventory(GameObject item)
 {
     if (item.tag == GameManager_References.batteryTag)
     {
         batteryCounter++;
         _itemsInInventory.Add(item.tag);
         Destroy(item);
         UpdateInventory();
         batteryCollected = true;
         _soundManager.PlaySoundForPlayer(Player_SoundHolder.collectUsable);
     }
     else if (item.tag == GameManager_References.fuelTag)
     {
         fuelCounter++;
         _itemsInInventory.Add(item.tag);
         Destroy(item);
         UpdateInventory();
         fuelCollected = true;
         _soundManager.PlaySoundForPlayer(Player_SoundHolder.collectUsable);
     }
     else if (item.tag == GameManager_References.gunTag)
     {
         _itemsInInventory.Add(item.tag);
         laserGunOnPlayer.SetActive(true);
         Destroy(item);
         _laserGunSprite.color     = new Color(255f, 255f, 255f);
         _laserGunSpriteMenu.color = new Color(255f, 255f, 255f);
         laserGunCollected         = true;
         _soundManager.PlaySoundForPlayer(Player_SoundHolder.collectItem);
     }
     else if (item.tag == GameManager_References.wheelsTag)
     {
         _itemsInInventory.Add(item.tag);
         Destroy(item);
         _wheelSprite.color     = new Color(255f, 255f, 255f);
         _wheelSpriteMenu.color = new Color(255f, 255f, 255f);
         wheelsCollected        = true;
         _soundManager.PlaySoundForPlayer(Player_SoundHolder.collectItem);
     }
     else if (item.tag == GameManager_References.springsTag)
     {
         GetComponent <Player_Controller>().enableJump = true;
         _itemsInInventory.Add(item.tag);
         Destroy(item);
         _springsSprite.color     = new Color(255f, 255f, 255f);
         _springsSpriteMenu.color = new Color(255f, 255f, 255f);
         springsCollected         = true;
         _soundManager.PlaySoundForPlayer(Player_SoundHolder.collectItem);
     }
 }
Beispiel #2
0
    private void FixedUpdate()
    {
        float speed;

        GetInput(out speed);

        if (isChangeingWalkMode)
        {
            return;
        }

        bool isWalking = _movementType == MovementType.MOVE_WALK;

        if (!isWalking)
        {
            if (speed <= Mathf.Abs(0.1f))
            {
                _speed = Mathf.Lerp(_speed, speed, Time.fixedDeltaTime * 3.0f);
            }
            else
            {
                _speed = Mathf.Lerp(_speed, speed, Time.fixedDeltaTime);
            }
        }

        if (!_isJumping)
        {
            // always move along the camera forward as it is the direction that it being aimed at
            Vector3 desiredMove = transform.forward * _input.y + transform.right * _input.x;

            if (isWalking)
            {
                _moveDirection.x = desiredMove.x * speed;
                _moveDirection.z = desiredMove.z * speed;
            }
            else
            {
                _moveDirection.x = desiredMove.x * _speed;
                _moveDirection.z = desiredMove.z * _speed;
            }

            //// get a normal for the surface that is being touched to move along it
            RaycastHit hitInfo;
            Physics.SphereCast(transform.position, _controller.radius, Vector3.down, out hitInfo,
                               _controller.height / 2.2f, Physics.AllLayers, QueryTriggerInteraction.Ignore);
            desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;

            if (isWalking)
            {
                _moveDirection.x = desiredMove.x * speed;
                _moveDirection.z = desiredMove.z * speed;
            }
            else
            {
                _moveDirection.x = desiredMove.x * _speed;
                _moveDirection.z = desiredMove.z * _speed;
            }
        }

        if (_controller.isGrounded)
        {
            if (_movementType == MovementType.MOVE_WALK)
            {
                if (_jump)
                {
                    _moveDirection.y     = jumpSpeed;
                    _jump                = false;
                    _isJumping           = true;
                    _isPreviouslyJumping = true;
                    _soundManager.PlaySoundForPlayer(Player_SoundHolder.jumpSound);
                }
            }
        }
        else
        {
            _moveDirection += Physics.gravity * gravityMultiplier * Time.deltaTime;
        }

        _controller.Move(_moveDirection * Time.fixedDeltaTime);

        animator.SetFloat("Speed", _controller.velocity.magnitude);

        if (_movementType == MovementType.MOVE_WHEEL)
        {
            if (_speed > 0.1f && !_isWheelSoundStarted)
            {
                _isWheelSoundStarted = true;
                _soundManager.PlaySoundForPlayer(Player_SoundHolder.wheelSound, true);
            }

            if (_isWheelSoundStarted)
            {
                Player_SoundHolder.audioSource.pitch = _speed / wheelModeSpeed;
            }
        }

        if (_isJumping || _movementType != MovementType.MOVE_WALK)
        {
            return;
        }

        ProgressStepCycle(speed);
    }