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; [SerializeField] GameObject _pterodactylPrefab; const int NUM_CLOUDS = 8; const float START_X = 1300; const float PTERODACTYL_CHANCE = .15f; [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; if (Random.Range(0f,1f)< PTERODACTYL_CHANCE) { bird = GameObject.Instantiate(_pterodactylPrefab); } else { 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); } } }