示例#1
0
    void Update()
    {
        if (_inputAvailable)
        {
            if (_currentPlayer.IsAvailable())
            {
                // test world switch
                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    Debug.Log("1 input!");
                    if (0 != Loop.WorldManager.GetCurrentWorldIndex())
                    {
                        _observer.SwitchWorld((Loop.WorldName) 0);
                    }
                }

                if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    if (1 != Loop.WorldManager.GetCurrentWorldIndex())
                    {
                        _observer.SwitchWorld((Loop.WorldName) 1);
                    }
                }

                if (Input.GetKeyDown(KeyCode.Q))
                {
                    _observer.SwitchWorld(Loop.WorldManager.GetPrevWorldName());
                }

                if (Input.GetKeyDown(KeyCode.Tab))
                {
                    _observer.SwitchWorld((Loop.WorldName)(
                                              (1 + Loop.WorldManager.GetCurrentWorldIndex()) % Loop.WorldConstants.WORLDS_NUM));
                }

                // 侦测跳跃按钮输入
                if (ct.isGrounded)
                {
                    _moveDirection = Vector3.zero;

                    if (Input.GetButton("Jump"))
                    {
                        _moveDirection.y = jumpSpeed;
                    }
                }

                float x = 0;

                // 转向
                if ((x = Input.GetAxis("Horizontal")) < 0)
                {
                    transform.rotation = Quaternion.Euler(new Vector3(0, -90, 0));
                }
                else if (x > 0)
                {
                    transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
                }

                // horizontal move
                _moveDirection.x = x * moveSpeed;
            }

            // 侦测地图切换按钮输入
            if (Input.GetKeyDown(KeyCode.M))
            {
                Debug.Log("M!");

                if (_isMapFlag == false)
                {
                    if (_camMain != null)
                    {
                        _camMain.camera.enabled = false;
                    }
                    if (_camMap != null)
                    {
                        _camMap.camera.enabled = true;
                    }
                    _isMapFlag = true;
                }
                else if (_isMapFlag == true)
                {
                    if (_camMain != null)
                    {
                        _camMain.camera.enabled = true;
                    }
                    if (_camMap != null)
                    {
                        _camMap.camera.enabled = false;
                    }
                    _isMapFlag = false;
                }
            }

            // gravity
            _moveDirection.y -= gravity * Time.deltaTime;

            ct.Move(_moveDirection * Time.deltaTime);
        } // end if(_inputAvailable)
    }