Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Mission : MonoBehaviour {
- public Transform[] spawnPoints;
- public string[] directions;
- public float[] civilistsSpawnsEasy;
- public float[] civilistsSpawnsNormal;
- public float[] civilistsSpawnsHard;
- public float[] zombieSpawnsEasy;
- public float[] zombieSpawnsNormal;
- public float[] zombieSpawnsHard;
- GUIStyle largeFont;
- public Font MyFont;
- public float startTime;
- private float ast;
- ///
- public float maxTime;
- public int minSaved;
- public int minKilled;
- public Transform Zombie;
- public Transform Civilist;
- ///
- private int mode;
- public Texture2D failTexture;
- public Texture2D WonTexture;
- public Texture2D mainMenuTexture;
- public Texture2D nextTexture;
- public Texture2D restartTexture;
- public Texture2D skip5Texture; ///
- private bool won;
- private bool failed;
- public AudioClip endAudio;
- // Use this for initialization
- void Start ()
- {
- Invoke( "End", maxTime + startTime );
- mode = PlayerPrefs.GetInt( "Mode" );
- won =false;
- failed = false;
- ast = Time.time;
- if( mode == 1 )
- {
- for( int i = 0; i < civilistsSpawnsEasy.Length; i++ )
- {
- SendMessage( "SpawnCivi", i + startTime );
- SendMessage( "SpawnZombie", i + startTime );
- }
- }
- if( mode == 2 )
- {
- for( int i = 0; i < civilistsSpawnsNormal.Length; i++ )
- {
- SendMessage( "SpawnCivi", i + startTime );
- SendMessage( "SpawnZombie", i + startTime );
- }
- }
- if( mode == 3 )
- {
- for( int i = 0; i < civilistsSpawnsHard.Length; i++ )
- {
- SendMessage( "SpawnCivi", i + startTime );
- SendMessage( "SpawnZombie", i + startTime );
- }
- }
- largeFont = new GUIStyle();
- largeFont.fontSize = 32;
- }
- IEnumerator SpawnCivi( int i )
- {
- if( mode == 1 )
- {
- if( i < civilistsSpawnsEasy.Length && civilistsSpawnsEasy[i] != null )
- yield return new WaitForSeconds( civilistsSpawnsEasy[i] );
- }
- else if( mode == 2 )
- {
- if( i < civilistsSpawnsNormal.Length && civilistsSpawnsNormal[i] != null )
- yield return new WaitForSeconds( civilistsSpawnsNormal[i] );
- }
- else if( mode == 3 )
- {
- if( i < civilistsSpawnsHard.Length && civilistsSpawnsHard[i] != null )
- yield return new WaitForSeconds( civilistsSpawnsHard[i] );
- }
- if( mode <= 3 && i < spawnPoints.Length && i < directions.Length )
- {
- Transform c = Instantiate( Civilist, spawnPoints[i].position, Quaternion.identity ) as Transform;
- c.SendMessage( directions[i] );
- SendMessage( "SpawnCivi", i );
- }
- }
- IEnumerator SpawnZombie( int i )
- {
- if( mode == 1 )
- {
- if( i < zombieSpawnsEasy.Length && zombieSpawnsEasy[i] != null )
- yield return new WaitForSeconds( zombieSpawnsEasy[i] );
- }
- else if( mode == 2 )
- {
- if( i < zombieSpawnsNormal.Length && zombieSpawnsNormal[i] != null )
- yield return new WaitForSeconds( zombieSpawnsNormal[i] );
- }
- else if( mode == 3 )
- {
- if( i < zombieSpawnsHard.Length && zombieSpawnsHard[i] != null )
- yield return new WaitForSeconds( zombieSpawnsHard[i] );
- }
- if( mode <= 3 && i < spawnPoints.Length && i < directions.Length )
- {
- Transform c = Instantiate( Zombie, spawnPoints[i].position, Quaternion.identity ) as Transform;
- c.SendMessage( directions[i] );
- SendMessage( "SpawnZombie", i );
- }
- }
- void End()
- {
- audio.clip = endAudio;
- audio.Play();
- if( CivilistManager.killedZombies >= minKilled && CivilistManager.savedCivilists >= minSaved )
- {
- Win ();
- }
- else
- {
- Fail ();
- }
- }
- void Fail()
- {
- failed = true;
- Time.timeScale = 0;
- }
- void Win()
- {
- won = true;
- Time.timeScale = 0;
- }
- void OnGUI()
- {
- GUI.skin.font = MyFont;
- GUI.Label( new Rect( 0,0, Screen.width/6, 20 ), "<color=white>Civilians saved:</color>" + CivilistManager.savedCivilists + " / " + minSaved, largeFont );
- GUI.Label( new Rect( 0,33, Screen.width/6, 20 ), "<color=lightblue>Time left:</color>" + (int) (ast+maxTime - Time.time), largeFont );
- GUI.Label( new Rect( 0,66, Screen.width/6, 20 ), "<color=red>Zombies killed:</color>" + CivilistManager.killedZombies + " / " + minKilled, largeFont );
- if( GUI.Button( new Rect( Screen.width - Screen.width/10,0, Screen.width/10, 40 ), restartTexture) )
- {
- mode = 1000;
- CancelInvoke();
- Start ();
- Time.timeScale = 1;
- Application.LoadLevel( Application.loadedLevel );
- }
- if( GUI.Button( new Rect( Screen.width - Screen.width/10,40, Screen.width/10, 40 ), skip5Texture) ) //////
- {
- CancelInvoke( "End" );
- Invoke( "End", 1 );
- }
- if( won )
- {
- GUI.DrawTexture( new Rect( Screen.width/3, Screen.height/3, Screen.width/3, Screen.height/20 ), WonTexture );
- if( GUI.Button( new Rect( Screen.width/3, Screen.height/3 + Screen.height/20, Screen.width/6, Screen.height/20 ), mainMenuTexture ) )
- {
- Time.timeScale = 1;
- Application.LoadLevel( 0 );
- }
- if( GUI.Button( new Rect( Screen.width/3 + Screen.width/6, Screen.height/3 + Screen.height/20, Screen.width/6, Screen.height/20 ), nextTexture ) )
- {
- Time.timeScale = 1;
- Application.LoadLevel( Application.loadedLevel + 1 );
- }
- }
- if( failed )
- {
- GUI.DrawTexture( new Rect( Screen.width/3, Screen.height/3, Screen.width/3, Screen.height/10 ), failTexture );
- if( GUI.Button( new Rect( Screen.width/3, Screen.height/3 + Screen.height/10, Screen.width/6, Screen.height/20 ), mainMenuTexture ) )
- {
- Time.timeScale = 1;
- Application.LoadLevel( 0 );
- }
- if( GUI.Button( new Rect( Screen.width/3 + Screen.width/6, Screen.height/3 + Screen.height/10, Screen.width/6, Screen.height/20 ), restartTexture ) )
- {
- mode = 1000;
- CancelInvoke();
- Start ();
- Time.timeScale = 1;
- Application.LoadLevel( Application.loadedLevel );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement