GameManager.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; //シーンをロードする際に必要 public class GameManager : MonoBehaviour { public GameObject[] targetArray; private int count; private float time; private int vecY; public Text timeUp; private float lastTime = 8.0f; public GameObject retryButton; //リトライボタンを入れる変数 void Start() { count = 0; retryButton.SetActive(false); //リトライボタンを非表示 } void Update() { if(count == targetArray.Length) { lastTime -= Time.deltaTime; if(lastTime <= 0 ) { timeUp.text = "TIME UP"; GetComponent<BallShot>().enabled = false; retryButton.SetActive(true); //リトライボタンを表示 } } else { time -= Time.deltaTime; if(time <= 0.0f) { vecY = Random.Range(0,12); Instantiate(targetArray[count],new Vector3(-40, vecY, 30),Quaternion.identity); time = 5.0f; count++; } } } //シーンを再ロードする(リトライ) public void Retry() { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } } |