UI Flashcards
using TMPro;
private int score;
public TextMeshProUGUI scoreText;
void Start() { score=0; scoreText.text = "Score: " + score; }
void Start() { UpdateScore(0); }
public void UpdateScore(int scoreToAdd) { score+= scoreToAdd; scoreText.text = "Score: "+score; }
IEnumerator SpawnTarget() { while (true){ UpdateScore(5);} }
private GameManager gameManager;
void Start(){ gameManager=GameObject.Find("Game Manager").GetComponent < GameManager>(); }
private void MouseDown() { Destroy(gameObject); gameManager.UpdateScore(5); }
public TextMeshProUGUI gameOverText;
public void GameOver()
{
gameOverText.gameObject.SetActive(true);
}
(No script Target) private void OnTrigerEnter(Collider other) { if (!gameObject.CompareTag("Bad")) { gameManager.GameOver(); } }
public bool isGameActive;
(GameManager) (Start) isGameActive = true; (public void GameOver()) isGameActive = false; (IEnumerator SpawnTarget()) while (isGameActive); (Script Target) private void OnMouseDown() {if (gameManager.isGameActive) { Todas as funções aqui dentro }}
(Scrip GameManager)
using UnityEngine.SceneManagement;
public void RestartGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
(script GameManager)
using UnityEngine.UI;
public Button restartButton;
public void GameOver()
{
restartButton.gameObject.SetActive(true);
}
(DifficultyButton)
using UnityEngine.UI
private Button button;
private GameManager gameManager;
public int difficulty;
(Start)
button=GetComponent < Button >();
gameManager=GameObject.Find(“Game Manager”).GetComponent < GameManager >();
button.onClick.AddListener(SetDifficulty);
void SetDifficulty()
{
Debug.Log(gameObject.name +”was clicked”);
gameManager.StartGame(difficulty);
}
(GameManager)
public GameObject titleScreen;
void StartGame(int difficulty) { ..... spawnRate /= difficulty; titleScreen.gameObject.SetActive(false); }
using UnityEngine.SceneManagement;
Carregar as cenas do jogo
public void StartNew()
{
SceneManager.LoadScene(1);
}
using UnityEditor;
fazer botão sair do jogo)
public void Exit() { #if UNITY_EDITOR EditorApplication.ExitPlaymode(); #else Application.Quit(); #endif }