/// <summary>
 /// Checks for input toggling visibility settings.
 /// </summary>
 private void Update()
 {
     if (InputUtil.GetKey(KeyCode.Tab))
     {
         keyTimer.Run();
     }
 }
        /// <summary>
        /// Moves the player around when keys are pressed.
        /// </summary>
        private void Move()
        {
            if (!vrCamera)
            {
                Vector2 mouseMovement = InputUtil.GetMouseMovement() * turnSpeed;
                transform.Rotate(-mouseMovement.y, mouseMovement.x, 0);
                Vector3 rotation = transform.eulerAngles;
                rotation.z = 0;
                if (rotation.x > 180)
                {
                    rotation.x = Mathf.Max(rotation.x, 360 - maxPitch);
                }
                else
                {
                    rotation.x = Mathf.Min(rotation.x, maxPitch);
                }
                transform.eulerAngles = rotation;
            }

            Vector3 targetDirection = Vector3.zero;

            targetDirection += Vector3.right * Input.GetAxis("Horizontal");
            targetDirection += Vector3.forward * Input.GetAxis("Vertical");

            float speedScale = Mathf.Min(1, Vector3.Magnitude(targetDirection));

            targetDirection   = RotateFacing(targetDirection);
            targetDirection.y = 0;
            targetDirection.Normalize();
            targetDirection *= speedScale;

            if (noClip)
            {
                if (InputUtil.GetKey(KeyCode.LeftShift, KeyCode.RightShift, KeyCode.PageDown))
                {
                    targetDirection += Vector3.down;
                }
                if (InputUtil.GetKey(KeyCode.Space, KeyCode.PageUp))
                {
                    targetDirection += Vector3.up;
                }
                targetDirection.Normalize();
            }

            targetDirection *= maxSpeed;
            moveDirection    = Vector3.MoveTowards(moveDirection, targetDirection, acceleration);

            if (noClip)
            {
                controller.Move(moveDirection * Time.fixedDeltaTime);
            }
            else
            {
                controller.SimpleMove(moveDirection);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks for the user resetting the level.
        /// </summary>
        private void Update()
        {
            if (!_levelRequested && InputUtil.GetKeyDown(KeyCode.G) && Input.GetKey(KeyCode.LeftShift))
            {
                GetComponent <LevelCreator>().RequestLevel();
            }

            if (isPlaying && !PauseHandler.instance.paused)
            {
                if (!_isCountingDown)
                {
                    _currentTime += Time.deltaTime;
                }

                if (Input.GetButton("Reset"))
                {
                    if (InputUtil.GetKey(KeyCode.LeftShift))
                    {
                        RestartScene();
                    }
                    else
                    {
                        ResetLevel();
                    }
                }
                else if (CountLemmings() == 0 &&
                         lemmingSpawner != null &&
                         lemmingSpawner.IsFinished() &&
                         !pathRenderer.visible)
                {
                    numDeaths++;
                    if (showPath)
                    {
                        pathRenderer.visible        = true;
                        PlayerMover.instance.noClip = true;
                        isPlaying = false;
                    }
                    else
                    {
                        ResetLevel();
                    }
                }

                if (InputUtil.GetKeyDown(KeyCode.O))
                {
                    _freezeLemmings = !freezeLemmings;
                }
            }
        }