fork download
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.SceneManagement;
  4.  
  5. public class GameController : MonoBehaviour
  6. {
  7. public GameObject hazard;
  8. public int hazardCount;
  9. public float spawnWait;
  10. public float startWait;
  11. public float waveWait;
  12.  
  13. public GUIText sorceText;
  14. public GUIText restartText;
  15. public GUIText gameOverText;
  16. public GUIText testText;
  17. private int score;
  18.  
  19. private bool gameOver;
  20. private bool restart;
  21.  
  22. public static float xMin, xMax, yMin, yMax;
  23.  
  24. void Start ()
  25. {
  26. testText.text = "start";
  27. Debug.Log ("Start ");
  28.  
  29. Camera cam = Camera.main;
  30.  
  31. float CamCentX = cam.gameObject.transform.position.x;
  32. float CamCentY = cam.gameObject.transform.position.y;
  33.  
  34. float Camheight = 2f * cam.orthographicSize;
  35. float Camwidth = Camheight * cam.aspect;
  36.  
  37. xMin = CamCentX - Camwidth/2.0f;
  38. xMax = CamCentX + Camwidth/2.0f - hazard.transform.localScale.x;
  39. yMin = CamCentY - Camheight/2.0f;
  40. yMax = CamCentY + Camheight/2.0f;
  41.  
  42. gameOver = false;
  43. restart = false;
  44. restartText.text = "";
  45. gameOverText.text = "";
  46. score = 0;
  47. UpdateScore ();
  48. StartCoroutine (SpawnWaves ());
  49.  
  50. }
  51.  
  52.  
  53. float lastClickTime = 0.0f;
  54. float catchTime = 0.25f;
  55. void Update(){
  56. if (restart) {
  57. if(Input.touchCount > 0 || Input.GetKeyDown(KeyCode.R)){
  58. if(Time.time-lastClickTime<catchTime){
  59. //double click
  60. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex) ;
  61. //print("done:"+(Time.time-lastClickTime).ToString());
  62. }else{
  63. //normal click
  64. print("miss:"+(Time.time-lastClickTime).ToString());
  65. }
  66. lastClickTime=Time.time;
  67. }
  68. }
  69. }
  70.  
  71.  
  72.  
  73. IEnumerator SpawnWaves(){
  74. yield return new WaitForSeconds (startWait);
  75. while (true)
  76. {
  77. testText.text = "In while (true), \nT = " + Time.time;
  78. for (int i = 0; i < hazardCount; i++)
  79. {
  80. //i++;
  81. testText.text = xMin + "," + xMax + "," + yMax+"\n i:"+i+", cnt:"+hazardCount;
  82. testText.text += "\nwait" + spawnWait + "," + waveWait + ",T=" + Time.time + "\n";
  83. testText.text += spawnWait+", "+startWait+", "+ waveWait;
  84. //testText.text = "CreatHazard:" + i;
  85. Vector3 spawnPosition = new Vector3 (Random.Range (xMin, xMax), yMax, 0);
  86. Quaternion spawnRotation = Quaternion.identity;
  87. Instantiate (hazard, spawnPosition, transform.rotation);
  88.  
  89. yield return new WaitForSeconds (spawnWait);
  90. }
  91. yield return new WaitForSeconds (waveWait);
  92.  
  93. if (gameOver) {
  94. testText.text = "In gameOver, \nT = " + Time.time;
  95. //restartText.text = "Press 'R' to Restart";
  96. restartText.text = "Double click to Restart";
  97. restart = true;
  98. break;
  99. }
  100. }
  101. }
  102.  
  103. public void AddScore (int newScoreValue)
  104. {
  105. score += newScoreValue;
  106. UpdateScore ();
  107. }
  108.  
  109. void UpdateScore ()
  110. {
  111. sorceText.text = "Score: " + score;
  112. }
  113.  
  114. public void GameOver(){
  115. gameOverText.text = "Game Over !!";
  116. gameOver = true;
  117. }
  118. }
  119.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(1,7): error CS0246: The type or namespace name `UnityEngine' could not be found. Are you missing an assembly reference?
prog.cs(3,7): error CS0246: The type or namespace name `UnityEngine' could not be found. Are you missing an assembly reference?
prog.cs(5,31): error CS0246: The type or namespace name `MonoBehaviour' could not be found. Are you missing an assembly reference?
prog.cs(7,9): error CS0246: The type or namespace name `GameObject' could not be found. Are you missing an assembly reference?
prog.cs(13,9): error CS0246: The type or namespace name `GUIText' could not be found. Are you missing an assembly reference?
prog.cs(14,9): error CS0246: The type or namespace name `GUIText' could not be found. Are you missing an assembly reference?
prog.cs(15,9): error CS0246: The type or namespace name `GUIText' could not be found. Are you missing an assembly reference?
prog.cs(16,9): error CS0246: The type or namespace name `GUIText' could not be found. Are you missing an assembly reference?
Compilation failed: 8 error(s), 0 warnings
stdout
Standard output is empty