示例#1
0
    private void SwitchState(ControllerState newState)
    {
        switch (_placeMode)
        {
        case ControllerState.Adjusting:
            transform.SetParent(null);
            _playerModel.transform.rotation = Quaternion.Euler(_playerModel.transform.rotation.eulerAngles.y * Vector3.up);
            _adjustedCannon = null;
            break;
        }
        switch (newState)
        {
        case ControllerState.Placing:
            _spawnableCannon = Instantiate(Resources.Load <PlacableCannon>("MagnetCannon"), _playerModel.transform.position + _playerModel.transform.forward * 3 + Vector3.down * 0.1f, _playerModel.transform.rotation, _playerModel.transform);
            //_spawnableCannon.transform.Rotate(Vector3.up, 90);
            _spawnableCannon.EnableBlueprintMode();

            foreach (Collider c in _spawnableCannon.GetComponentsInChildren <Collider>())
            {
                c.enabled = false;
            }

            break;

        case ControllerState.Adjusting:
            LockCursor();
            _adjustedCannon = _targetedCannon;
            break;

        case ControllerState.Moving:
            LockCursor();

            break;
        }
        _placeMode = newState;
    }
示例#2
0
    private void Update()
    {
        if (_placeMode != ControllerState.Adjusting)
        {
            RaycastHit rch;
            if (Physics.Raycast(_playerModel.transform.position + Vector3.up, _playerModel.transform.forward, out rch, _interactionDistance, 1 << 9))
            {
                _targetedCannon = rch.transform.GetComponent <PlacableCannon>();
                _targetedCannon.SetHighlighted(true);
            }
            else
            {
                if (_targetedCannon != null)
                {
                    _targetedCannon.SetHighlighted(false);
                }
                _targetedCannon = null;
            }

            movement = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));

            _isJumping = Input.GetButton("Jump");

            if (!_isJumping && _jetPackFuel < _jetPackFuelMax)
            {
                _jetPackFuel = Mathf.Clamp(_jetPackFuel + _jetPackRefuelRate * Time.deltaTime, 0, _jetPackFuelMax);
            }

            if (MouseLocked)
            {
                _playerModel.transform.Rotate(0, Input.GetAxis("Mouse X") * mouseSensitivity.x, 0);

                if (cameraTarget != null)
                {
                    Vector3 cameraTargetPos = cameraTarget.transform.localPosition;
                    cameraTargetPos.y = Mathf.Clamp(cameraTargetPos.y + Input.GetAxis("Mouse Y") * mouseSensitivity.y, _cameraHeightMin, _cameraHeightMax);
                    cameraTarget.transform.localPosition = cameraTargetPos;
                }
            }
        }
        else
        {
            _rb.Sleep();
            transform.SetPositionAndRotation(_adjustedCannon.adjustSeat.position, _adjustedCannon.adjustSeat.rotation);
            _playerModel.transform.rotation = _adjustedCannon.adjustSeat.rotation;

            _adjustedCannon.AddAngle(Input.GetAxis("Mouse Y"));
            _adjustedCannon.AddRotation(Input.GetAxis("Mouse X"));
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            switch (_placeMode)
            {
            case ControllerState.Moving:
                if (_targetedCannon != null)
                {
                    SwitchState(ControllerState.Adjusting);
                }
                else
                {
                    SwitchState(ControllerState.Placing);
                }
                break;

            case ControllerState.Placing:
                if (cantBuild)
                {
                    return;
                }
                _spawnableCannon.transform.SetParent(null);
                _spawnableCannon.GetComponent <CannonCantBuild>().placed = true;
                _spawnableCannon.DisableBlueprintMode();
                foreach (Collider c in _spawnableCannon.GetComponentsInChildren <Collider>())
                {
                    c.enabled = true;
                }
                SwitchState(ControllerState.Moving);
                break;

            case ControllerState.Adjusting:
                SwitchState(ControllerState.Moving);
                break;
            }
        }
    }