Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Mission : MonoBehaviour {
  5.  
  6. public Transform[] spawnPoints;
  7. public string[] directions;
  8. public float[] civilistsSpawnsEasy;
  9. public float[] civilistsSpawnsNormal;
  10. public float[] civilistsSpawnsHard;
  11. public float[] zombieSpawnsEasy;
  12. public float[] zombieSpawnsNormal;
  13. public float[] zombieSpawnsHard;
  14.  
  15. GUIStyle largeFont;
  16.  
  17. public Font MyFont;
  18. public float startTime;
  19. private float ast;
  20.  
  21.  
  22. ///
  23.  
  24.  
  25. public float maxTime;
  26.  
  27. public int minSaved;
  28. public int minKilled;
  29.  
  30.  
  31. public Transform Zombie;
  32. public Transform Civilist;
  33.  
  34. ///
  35.  
  36. private int mode;
  37.  
  38. public Texture2D failTexture;
  39. public Texture2D WonTexture;
  40. public Texture2D mainMenuTexture;
  41. public Texture2D nextTexture;
  42. public Texture2D restartTexture;
  43. public Texture2D skip5Texture; ///
  44.  
  45. private bool won;
  46. private bool failed;
  47.  
  48. public AudioClip endAudio;
  49.  
  50. // Use this for initialization
  51. void Start ()
  52.  
  53. {
  54. Invoke( "End", maxTime + startTime );
  55. mode = PlayerPrefs.GetInt( "Mode" );
  56. won =false;
  57. failed = false;
  58. ast = Time.time;
  59. if( mode == 1 )
  60. {
  61. for( int i = 0; i < civilistsSpawnsEasy.Length; i++ )
  62. {
  63. SendMessage( "SpawnCivi", i + startTime );
  64. SendMessage( "SpawnZombie", i + startTime );
  65. }
  66. }
  67. if( mode == 2 )
  68. {
  69. for( int i = 0; i < civilistsSpawnsNormal.Length; i++ )
  70. {
  71. SendMessage( "SpawnCivi", i + startTime );
  72. SendMessage( "SpawnZombie", i + startTime );
  73. }
  74. }
  75. if( mode == 3 )
  76. {
  77. for( int i = 0; i < civilistsSpawnsHard.Length; i++ )
  78. {
  79. SendMessage( "SpawnCivi", i + startTime );
  80. SendMessage( "SpawnZombie", i + startTime );
  81. }
  82. }
  83.  
  84. largeFont = new GUIStyle();
  85. largeFont.fontSize = 32;
  86. }
  87.  
  88.  
  89. IEnumerator SpawnCivi( int i )
  90. {
  91. if( mode == 1 )
  92. {
  93. if( i < civilistsSpawnsEasy.Length && civilistsSpawnsEasy[i] != null )
  94. yield return new WaitForSeconds( civilistsSpawnsEasy[i] );
  95. }
  96.  
  97. else if( mode == 2 )
  98. {
  99. if( i < civilistsSpawnsNormal.Length && civilistsSpawnsNormal[i] != null )
  100. yield return new WaitForSeconds( civilistsSpawnsNormal[i] );
  101. }
  102.  
  103. else if( mode == 3 )
  104. {
  105. if( i < civilistsSpawnsHard.Length && civilistsSpawnsHard[i] != null )
  106. yield return new WaitForSeconds( civilistsSpawnsHard[i] );
  107. }
  108.  
  109. if( mode <= 3 && i < spawnPoints.Length && i < directions.Length )
  110. {
  111. Transform c = Instantiate( Civilist, spawnPoints[i].position, Quaternion.identity ) as Transform;
  112. c.SendMessage( directions[i] );
  113. SendMessage( "SpawnCivi", i );
  114. }
  115. }
  116. IEnumerator SpawnZombie( int i )
  117. {
  118. if( mode == 1 )
  119. {
  120. if( i < zombieSpawnsEasy.Length && zombieSpawnsEasy[i] != null )
  121. yield return new WaitForSeconds( zombieSpawnsEasy[i] );
  122. }
  123.  
  124. else if( mode == 2 )
  125. {
  126. if( i < zombieSpawnsNormal.Length && zombieSpawnsNormal[i] != null )
  127. yield return new WaitForSeconds( zombieSpawnsNormal[i] );
  128. }
  129.  
  130. else if( mode == 3 )
  131. {
  132. if( i < zombieSpawnsHard.Length && zombieSpawnsHard[i] != null )
  133. yield return new WaitForSeconds( zombieSpawnsHard[i] );
  134. }
  135.  
  136. if( mode <= 3 && i < spawnPoints.Length && i < directions.Length )
  137. {
  138. Transform c = Instantiate( Zombie, spawnPoints[i].position, Quaternion.identity ) as Transform;
  139. c.SendMessage( directions[i] );
  140. SendMessage( "SpawnZombie", i );
  141. }
  142. }
  143.  
  144. void End()
  145. {
  146. audio.clip = endAudio;
  147. audio.Play();
  148. if( CivilistManager.killedZombies >= minKilled && CivilistManager.savedCivilists >= minSaved )
  149. {
  150. Win ();
  151. }
  152. else
  153. {
  154. Fail ();
  155. }
  156. }
  157.  
  158. void Fail()
  159. {
  160. failed = true;
  161. Time.timeScale = 0;
  162. }
  163.  
  164. void Win()
  165. {
  166. won = true;
  167. Time.timeScale = 0;
  168. }
  169.  
  170. void OnGUI()
  171.  
  172.  
  173. {
  174. GUI.skin.font = MyFont;
  175. GUI.Label( new Rect( 0,0, Screen.width/6, 20 ), "<color=white>Civilians saved:</color>" + CivilistManager.savedCivilists + " / " + minSaved, largeFont );
  176. GUI.Label( new Rect( 0,33, Screen.width/6, 20 ), "<color=lightblue>Time left:</color>" + (int) (ast+maxTime - Time.time), largeFont );
  177. GUI.Label( new Rect( 0,66, Screen.width/6, 20 ), "<color=red>Zombies killed:</color>" + CivilistManager.killedZombies + " / " + minKilled, largeFont );
  178. if( GUI.Button( new Rect( Screen.width - Screen.width/10,0, Screen.width/10, 40 ), restartTexture) )
  179. {
  180. mode = 1000;
  181. CancelInvoke();
  182. Start ();
  183. Time.timeScale = 1;
  184. Application.LoadLevel( Application.loadedLevel );
  185. }
  186.  
  187.  
  188. if( GUI.Button( new Rect( Screen.width - Screen.width/10,40, Screen.width/10, 40 ), skip5Texture) ) //////
  189. {
  190. CancelInvoke( "End" );
  191.  
  192. Invoke( "End", 1 );
  193. }
  194.  
  195. if( won )
  196. {
  197. GUI.DrawTexture( new Rect( Screen.width/3, Screen.height/3, Screen.width/3, Screen.height/20 ), WonTexture );
  198. if( GUI.Button( new Rect( Screen.width/3, Screen.height/3 + Screen.height/20, Screen.width/6, Screen.height/20 ), mainMenuTexture ) )
  199. {
  200. Time.timeScale = 1;
  201. Application.LoadLevel( 0 );
  202. }
  203. if( GUI.Button( new Rect( Screen.width/3 + Screen.width/6, Screen.height/3 + Screen.height/20, Screen.width/6, Screen.height/20 ), nextTexture ) )
  204. {
  205. Time.timeScale = 1;
  206. Application.LoadLevel( Application.loadedLevel + 1 );
  207. }
  208. }
  209. if( failed )
  210. {
  211. GUI.DrawTexture( new Rect( Screen.width/3, Screen.height/3, Screen.width/3, Screen.height/10 ), failTexture );
  212. if( GUI.Button( new Rect( Screen.width/3, Screen.height/3 + Screen.height/10, Screen.width/6, Screen.height/20 ), mainMenuTexture ) )
  213. {
  214. Time.timeScale = 1;
  215. Application.LoadLevel( 0 );
  216. }
  217. if( GUI.Button( new Rect( Screen.width/3 + Screen.width/6, Screen.height/3 + Screen.height/10, Screen.width/6, Screen.height/20 ), restartTexture ) )
  218. {
  219. mode = 1000;
  220. CancelInvoke();
  221. Start ();
  222. Time.timeScale = 1;
  223. Application.LoadLevel( Application.loadedLevel );
  224. }
  225. }
  226. }
  227.  
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement