using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class Game : MonoBehaviour { // Start is called before the first frame update [SerializeField] GameObject _cloudPrefab; [SerializeField] GameObject _birdPrefab; const int NUM_CLOUDS = 6; const float START_X = 1300; [SerializeField] Text _victoryMessage; [SerializeField] Text _restartMessage; bool _victory = false; float _timeToNextBird = 0f; void Start() { _victoryMessage.enabled = false; _restartMessage.enabled = false; for (int i = 0; i < NUM_CLOUDS; ++i) { GameObject cloud = GameObject.Instantiate(_cloudPrefab); cloud.transform.position = new Vector3(Random.Range(START_X, START_X + 1920 + CloudWraparound.DISTANCE_OFF_LEFT_EDGE), cloud.transform.position.y, cloud.transform.position.z); } } public void Victory(string dragonName, Color color) { if (_victory) return; _victory = true; _restartMessage.enabled = true; _victoryMessage.enabled = true; _victoryMessage.text = dragonName.ToUpper() + " WINS!"; _victoryMessage.color = color; } void SpawnBird() { GameObject bird = GameObject.Instantiate(_birdPrefab); float y = Random.Range(0f, 1080f); bird.transform.position = new Vector3(2000f, y, 0f); _timeToNextBird = Random.Range(0f, 4f); } // Update is called once per frame void Update() { _timeToNextBird -= Time.deltaTime; if (_timeToNextBird < 0f) { SpawnBird(); } if (Input.GetKeyDown(KeyCode.R)) { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } } }