Created
December 24, 2021 17:30
-
-
Save EwertonBello/793091826db4381ab115f3eaa1de5158 to your computer and use it in GitHub Desktop.
Controle de temporizador, movimentos do player, posição aleatória da esfera no labirinto,colisão com esfera e ações da tela de resultado da partida Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
using UnityEngine.SceneManagement; | |
public class GameManager : MonoBehaviour | |
{ | |
[SerializeField] private float startTime = 30.0f; | |
private float timer; | |
private int timerSec; | |
[SerializeField] private Text timerText; | |
[SerializeField] private GameObject loseWindow; | |
void Start() | |
{ | |
timer = startTime; | |
} | |
void Update() | |
{ | |
if (timer > 0) | |
{ | |
Timer(); | |
} | |
else | |
{ | |
FinishGame(); | |
} | |
} | |
void FinishGame() | |
{ | |
loseWindow.SetActive(true); | |
Time.timeScale = 0; | |
} | |
void Timer() | |
{ | |
timer -= Time.deltaTime; | |
timerSec = (int) timer; | |
timerText.text = timerSec.ToString(); | |
} | |
public void Restart() | |
{ | |
Time.timeScale = 1; | |
timer = startTime; | |
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); | |
} | |
public void Exit() | |
{ | |
Debug.Log("Exiting..."); | |
Application.Quit(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerMove : MonoBehaviour | |
{ | |
[SerializeField] private float speed = 10.0f; | |
[SerializeField] private float rotationSpeed = 100.0f; | |
[SerializeField] private GameObject winnerWindow; | |
[SerializeField] private GameObject targetPrefab; | |
void Start() | |
{ | |
Instantiate(targetPrefab, GetRandomPosition(), Quaternion.identity); | |
} | |
void Update() | |
{ | |
float translation = Input.GetAxis("Vertical") * speed; | |
float rotation = Input.GetAxis("Horizontal") * rotationSpeed; | |
translation *= Time.deltaTime; | |
rotation *= Time.deltaTime; | |
transform.Translate(0, 0, translation); | |
transform.Rotate(0, rotation, 0); | |
} | |
private void OnTriggerEnter(Collider collision) | |
{ | |
Destroy(collision.transform.parent.gameObject); | |
FinishGame(); | |
} | |
void FinishGame() | |
{ | |
winnerWindow.SetActive(true); | |
Time.timeScale = 0; | |
} | |
Vector3 GetRandomPosition() | |
{ | |
Vector3[] positions = {new Vector3(-1.7f, 1.2f, -2.56f), | |
new Vector3(17.26f, 1.12f, -5.39f), | |
new Vector3(16.93f, 1.12f, 9.61f), | |
new Vector3(16.93f, 1.12f, 17.91f), | |
new Vector3(6.88f, 1.12f, 12.74f), | |
new Vector3(1.85f, 1.12f, -0.2f)}; | |
int randomNumber = Random.Range(0, positions.Length); | |
return positions[randomNumber]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment