示例#1
0
    void Update()
    {
        transform.position = _playerMover.GetRenderPosition();

        // Read camera look orientation from inputs and update local state.
        var orientation = updateOrientation();

        _headChild.transform.rotation = orientation;
        _movementDirection            = getMovementDirection(orientation);

        // Offset the camera's local position for the camera bobbing effect, and tell HUD to bob gun.
        var bob = _playerMover.GetSpeedRatio() * _cameraBobMagnitude * cameraBob(_cameraBobSpeed * Time.time);

        _cameraChild.transform.localPosition = bob.AsVector3WithZ(0f);
        _hud.SetGunBob(bob);

        // Handle firing new platforms when the primary mouse button is clicked, and we're not pausing time.
        if (_ableToShoot && Time.time > _timeLastShot + _minTimeBetweenShots && Input.GetMouseButtonDown(0) && !Input.GetMouseButton(1))
        {
            var platformObj = Instantiate(_platformPrefab, transform.position + Vector3.up * _playerHeight, Quaternion.identity);
            _currentPlatform = platformObj.GetComponent <PlatformController>();
            _currentPlatform.Init(this, _cameraChild.transform.rotation * Vector3.forward);
            _hud.AnimateGunShot();
            _sounds.PlayGunshotSound();
            _timeLastShot = Time.time;
            ScoreTracker.ShotCount++;
        }

        // Handle pausing time on platforms when the secondary mouse button is clicked.
        if (Input.GetMouseButtonDown(1))
        {
            foreach (var p in FindObjectsOfType <PlatformController>())
            {
                p.SetPaused(true);
            }
        }
        else if (Input.GetMouseButtonUp(1))
        {
            foreach (var p in FindObjectsOfType <PlatformController>())
            {
                p.SetPaused(false);
            }
        }

        _sounds.SetFootstepsPlaying(_playerMover.Standing && _movementDirection.sqrMagnitude > 0.5f);
    }