/// <summary> /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> void Update() { // If the game hasn't started yet, nothing happens if (gameStarted == false) { return; } // Delay the start of the game if (startDelay > 0) { startDelay -= Time.deltaTime; } else { //If the game is over, listen for the Restart and MainMenu buttons if (isGameOver == true) { //The jump button restarts the game if (Input.GetButtonDown(confirmButton)) { Restart(); } //The pause button goes to the main menu if (Input.GetButtonDown(pauseButton)) { MainMenu(); } } else { // If there is a player object, move it forward and turn it in the correct direction if (playerObject) { // If we are using mobile controls, turn left/right based on the tap side position on the screen if (Application.isMobilePlatform) { // If we have a steering wheel slider assigned, use it if (steeringWheel) { // If we press the mouse button, check our position relative to the screen center if (Input.GetMouseButton(0)) { playerDirection = steeringWheel.value; } else // Otherwise, if we didn't press anything, don't rotate and straighten up { steeringWheel.value = playerDirection = 0; } steeringWheel.transform.Find("Wheel").eulerAngles = Vector3.forward * playerDirection * -100; } else if (Input.GetMouseButton(0)) // If we press the mouse button, check our position relative to the screen center { // If we are to the right of the screen, rotate to the right if (Input.mousePosition.x > Screen.width * 0.5f) { playerDirection = 1; } else // Othwerwise, rotate to the left { playerDirection = -1; } } else // Otherwise, if we didn't press anything, don't rotate and straighten up { playerDirection = 0; } } else // Otherwise, use gamepad/keyboard controls { playerDirection = Input.GetAxis("Horizontal"); } // Calculate the rotation direction playerObject.Rotate(playerDirection); // Unused code that makes the player wrap around the edge of the game area if (wrapAroundGameArea == true) { if (playerObject.transform.position.x > gameArea.x * 0.5f) { playerObject.transform.position -= Vector3.right * gameArea.x; } if (playerObject.transform.position.x < gameArea.x * -0.5f) { playerObject.transform.position += Vector3.right * gameArea.x; } if (playerObject.transform.position.z > gameArea.y * 0.5f) { playerObject.transform.position -= Vector3.forward * gameArea.y; } if (playerObject.transform.position.z < gameArea.y * -0.5f) { playerObject.transform.position += Vector3.forward * gameArea.y; } } } //Toggle pause/unpause in the game if (Input.GetButtonDown(pauseButton)) { if (isPaused == true) { Unpause(); } else { Pause(true); } } } } }
void Update() { // Если игра еще не началась, ничего не происходит if (gameStarted == false) { return; } // Отложите начало игры if (startDelay > 0) { startDelay -= Time.deltaTime; } else { //Если игра закончена, активировать кнопки Перезапуска и MainMenu if (isGameOver == true) { // кнопка рестарт if (Input.GetButtonDown(confirmButton)) { Restart(); } //кнопка ставит игру на паузу и переводит на главное меню if (Input.GetButtonDown(pauseButton)) { MainMenu(); } } else { // Если есть объект игрока, переместите его вперед и поверните в правильном направлении if (playerObject) { // Если мы используем мобильные элементы управления, поверните влево/вправо в зависимости от положения крана сбоку на экране if (Application.isMobilePlatform) { // Если у нас есть ползунок рулевого колеса, используйте его if (steeringWheel) { // Если мы нажмем кнопку мыши, проверьте наше положение относительно центра экрана if (Input.GetMouseButton(0)) { playerDirection = steeringWheel.value; } else // В противном случае, если мы ничего не нажимали, то тачка не вращается и не выпрямляется { steeringWheel.value = playerDirection = 0; } steeringWheel.transform.Find("Wheel").eulerAngles = Vector3.forward * playerDirection * -100; } else if (Input.GetMouseButton(0)) // Если мы нажмем кнопку мыши, проверьте наше положение относительно центра экрана { // Если мы находимся справа от экрана, повернитесь вправо if (Input.mousePosition.x > Screen.width * 0.5f) { playerDirection = 1; } else // иначе налево { playerDirection = -1; } } else // В противном случае, если мы ничего не нажимали, не вращайтесь и не выпрямляйтесь { playerDirection = 0; } } else // В противном случае используйте элементы управления геймпадом/клавиатурой { playerDirection = Input.GetAxis("Horizontal"); } // Вычисляем направление вращения playerObject.Rotate(playerDirection); // код, который заставляет игрока обернуться вокруг края игровой зоны if (wrapAroundGameArea == true) { if (playerObject.transform.position.x > gameArea.x * 0.5f) { playerObject.transform.position -= Vector3.right * gameArea.x; } if (playerObject.transform.position.x < gameArea.x * -0.5f) { playerObject.transform.position += Vector3.right * gameArea.x; } if (playerObject.transform.position.z > gameArea.y * 0.5f) { playerObject.transform.position -= Vector3.forward * gameArea.y; } if (playerObject.transform.position.z < gameArea.y * -0.5f) { playerObject.transform.position += Vector3.forward * gameArea.y; } } } //Переключение паузы/отмены паузы в игре if (Input.GetButtonDown(pauseButton)) { if (isPaused == true) { Unpause(); } else { Pause(true); } } } } }