Advertisement
Guest User

NukeTimer Script in C#

a guest
May 7th, 2018
4,322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 20.31 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.Video;
  4. using System.IO;
  5.  
  6. /**
  7.  *  US/UK NUCLEAR-STRIKE VIDEO PRANK
  8.  *  DEVELOPER NOTES : Anthony Smith 20/03/2018
  9.  *  COMPLETED SCRIPT 29/03/2018 - 00:33
  10.  *  ==========================================
  11.  *  Note: Nuclear warning prank with video for UK and the USA
  12.  *  TO-DO : nothing.
  13.  *
  14.  **/
  15.  
  16. public class NukeTimer : MonoBehaviour
  17. {
  18.     public TextMesh[] digits;
  19.     public AudioClip siren, intro_Speech, three_Minutes, two_Minutes, one_Minute, thirty_Seconds, fifteen_Seconds, ten_Seconds;
  20.     public AudioClip five_Seconds, klaxon, no_Test, attention, EAS_Sound;
  21.     public AudioClip US_Speech, US_three_Minutes, US_two_Minutes, US_one_Minute, US_thirty_Seconds, US_fifteen_Seconds, US_ten_Seconds, US_five_Seconds, US_no_Test;
  22.     public SpriteRenderer uk_Backdrop, us_Backdrop;
  23.     public VideoPlayer breaking_News, end_Static, end_Static_USA, USA_Intro;
  24.     private int timerDigit0 = 0, timerDigit1 = 4, timerDigit2 = 0, timerDigit3 = 0, timerDigit4 = 0, messageMarker = 0;
  25.     // default clock starts with 040000 (four minute countdown)
  26.     private float timerDigit5 = 0f, timerSpeed = 100f, letterPause = 0.01f;
  27.     private AudioSource soundSystem;
  28.     public TextMesh info_Line1, info_Line2, info_Line1USA, info_Line2USA, ending_Text;
  29.     private string messageToType1, messageToType2;
  30.     private string infoMessage1, infoMessage2;
  31.     private string typeText1, typeText2, typeEndText, endText;
  32.     private bool readyToType = true, readyToPlaySound = true, counterRunning;
  33.     string[] teletypeMessages = {
  34.         "We shall be on the air every hour, on the hour, stay tuned to this channel.",
  35.         "The 'all clear' message will also be given on this channel.",
  36.         "Radioactive fall-out which follows a nuclear explosion is many times more dangerous,",
  37.         "Especially if you are directly exposed to it in the open.",
  38.         "Roofs and walls offer substantial protection. The safest place is indoors.",
  39.         "Make sure gas and other fuel supplies are turned off and that all fires are extinguished.",
  40.         "If mains water is available, this can be used for fire-fighting.",
  41.         "The mains water supply may not be available for very long.",
  42.         "You should also refill all your containers for drinking water after the fires have been put out,",
  43.         "Water must not be used for flushing lavatories.",
  44.         "Use your water only for essential drinking and cooking purposes.",
  45.         "Water means life, Don't waste it.",
  46.         "Make your food stocks last, ration your supply, because it may have to last for 14 days or more.",
  47.         "If you have fresh food in the house, use this first to avoid wasting it, food in tins will keep.",
  48.         "If you live in an area where a fall out warning has been given,",
  49.         "Stay in your fall-out room until you are told it is safe to come out.",
  50.         "When the immediate danger has passed the sirens will sound a steady note.",
  51.         "The 'all clear' message will also be given on this channel.",
  52.         "If you leave the fall-out room to go to the lavatory or replenish food or water supplies,",
  53.         "Do NOT remain outside the room for a minute longer than is necessary.",
  54.         "Do NOT in any circumstances go outside the house, radioactive fall-out can KILL.",
  55.         "You cannot see it or feel it, but it is there.",
  56.         "Stay in your fall-out room until you hear the 'all clear' on the sirens.",
  57.         "If you go outside, you will bring danger to your family and you may die.",
  58.         "We shall be on the air every hour, on the hour, stay tuned to this channel.",
  59.         "Find shelter NOW."
  60.     };
  61.  
  62.     void Start ()
  63.     {
  64.         Cursor.visible = false;
  65.         // turn digits off to start
  66.         for (int disableDigit = 0; disableDigit < digits.Length; disableDigit++) {
  67.             digits [disableDigit].gameObject.SetActive (false);
  68.         }
  69.         info_Line1.GetComponent<Renderer> ().enabled = false; // turn off info text line 1 to start
  70.         info_Line2.GetComponent<Renderer> ().enabled = false; // turn off info text line 2 to start
  71.         info_Line1USA.GetComponent<Renderer> ().enabled = false; // USA version
  72.         info_Line2USA.GetComponent<Renderer> ().enabled = false; // USA version
  73.         ending_Text.GetComponent<Renderer> ().enabled = false; // turn off ending text line
  74.         if (PlayerPrefs.HasKey ("whichcountry")) { // check if user changed country
  75.         } else {
  76.             PlayerPrefs.SetInt ("whichcountry", 0); // country code, 0 for UK, 1 for USA - default UK
  77.         }
  78.         uk_Backdrop.enabled = false; // turn off backdrops to start
  79.         us_Backdrop.enabled = false;
  80.         counterRunning = false; // stopped here, wait for intro video to finish first
  81.         // Sound initialization
  82.         soundSystem = gameObject.GetComponent<AudioSource> ();
  83.         soundSystem.Stop (); // pause counter sound at start
  84.         if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  85.             breaking_News.enabled = true; // start the UK intro
  86.         } else {
  87.             USA_Intro.enabled = true; // start the USA intro
  88.         }
  89.         ReadEndingTextFile (); // the ending line of text a user can change
  90.         // Initialize the timer digits
  91.         digits [5].text = string.Format ("{0}", Mathf.Round (timerDigit5));
  92.         digits [4].text = string.Format ("{0}", Mathf.Round (timerDigit4));
  93.         digits [3].text = string.Format ("{0}", Mathf.Round (timerDigit3));
  94.         digits [2].text = string.Format ("{0}", Mathf.Round (timerDigit2));
  95.         digits [1].text = string.Format ("{0}", Mathf.Round (timerDigit1));
  96.         digits [0].text = string.Format ("{0}", Mathf.Round (timerDigit0));
  97.     }
  98.  
  99.     void Update ()
  100.     {
  101.         if (breaking_News.isActiveAndEnabled && breaking_News.frame == 1760) { // video has stopped playing (newsbreaking video has 1761 frames)
  102.             BeginCountdown ();
  103.         }
  104.         if (USA_Intro.isActiveAndEnabled && USA_Intro.frame == 843) { // video has stopped playing (US Intro video has 844 frames)
  105.             BeginCountdown ();
  106.         }
  107.         // end of UK static video with end text start-up
  108.         if (end_Static.isActiveAndEnabled && end_Static.frame >= 422) { // video has stopped playing (end_static video has 422 frames)
  109.             end_Static.enabled = false; // disable the static
  110.             Invoke ("StartEndText", 1.0f); // slight delay before we show the ending text
  111.             Invoke ("Quit", 11.0f); // quit after ten seconds or so...
  112.         }
  113.         // end of US static video
  114.         if (end_Static_USA.isActiveAndEnabled && end_Static_USA.frame >= 423) { // video has stopped playing (end_static USA video has 424 frames)
  115.             end_Static_USA.enabled = false; // disable the US static
  116.             Invoke ("StartEndText", 1.0f); // slight delay before we show the ending text
  117.             Invoke ("Quit", 11.0f); // quit after ten seconds or so...
  118.         }
  119.         // check time(s) and play SOUNDS
  120.         if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 5 && timerDigit3 == 9 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:59:00
  121.             readyToPlaySound = false;
  122.             if (PlayerPrefs.GetInt ("whichcountry") == 1) { // USA
  123.                 soundSystem.PlayOneShot (EAS_Sound); // play the EAS system tone on start-up
  124.             }
  125.             Invoke ("ResetReadyToPlaySound", 0.5f);
  126.         }
  127.         if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 5 && timerDigit3 == 8 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:58:00
  128.             readyToPlaySound = false;
  129.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  130.                 soundSystem.PlayOneShot (attention);
  131.             }
  132.             Invoke ("ResetReadyToPlaySound", 0.5f);
  133.         }
  134.         if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 5 && timerDigit3 == 4 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:55:00
  135.             readyToPlaySound = false;
  136.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  137.                 soundSystem.PlayOneShot (intro_Speech);
  138.             } else {
  139.                 soundSystem.PlayOneShot (US_Speech);
  140.             }
  141.             Invoke ("ResetReadyToPlaySound", 0.5f);
  142.         }
  143.         if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 2 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:20:00
  144.             readyToPlaySound = false;
  145.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  146.                 soundSystem.PlayOneShot (no_Test);
  147.             } else {
  148.                 soundSystem.PlayOneShot (US_no_Test);
  149.             }
  150.             Invoke ("ResetReadyToPlaySound", 0.5f);
  151.         }
  152.         if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 1 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:10:00
  153.             readyToPlaySound = false;
  154.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  155.                 soundSystem.PlayOneShot (no_Test);
  156.             } else {
  157.                 soundSystem.PlayOneShot (US_no_Test);
  158.             }
  159.             Invoke ("ResetReadyToPlaySound", 0.5f);
  160.         }
  161.         if (counterRunning && readyToPlaySound && timerDigit1 == 2 && timerDigit2 == 5 && timerDigit3 == 8 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:58:00
  162.             readyToPlaySound = false;
  163.             soundSystem.PlayOneShot (siren);
  164.             Invoke ("ResetReadyToPlaySound", 0.5f);
  165.         }
  166.         // 3 minute marker
  167.         if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:00:00
  168.             readyToPlaySound = false;
  169.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  170.                 soundSystem.PlayOneShot (three_Minutes);
  171.             } else {
  172.                 soundSystem.PlayOneShot (US_three_Minutes);
  173.             }
  174.             Invoke ("ResetReadyToPlaySound", 0.5f);
  175.         }
  176.         // 2 minute marker
  177.         if (counterRunning && readyToPlaySound && timerDigit1 == 2 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:00:00
  178.             readyToPlaySound = false;
  179.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  180.                 soundSystem.PlayOneShot (two_Minutes);
  181.             } else {
  182.                 soundSystem.PlayOneShot (US_two_Minutes);
  183.             }
  184.             Invoke ("ResetReadyToPlaySound", 0.5f);
  185.         }
  186.         // 1 minute marker
  187.         if (counterRunning && readyToPlaySound && timerDigit1 == 1 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:00:00
  188.             readyToPlaySound = false;
  189.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  190.                 soundSystem.PlayOneShot (one_Minute);
  191.             } else {
  192.                 soundSystem.PlayOneShot (US_one_Minute);
  193.             }
  194.             Invoke ("ResetReadyToPlaySound", 0.5f);
  195.         }
  196.         // 30 second marker
  197.         if (counterRunning && readyToPlaySound && timerDigit1 == 0 && timerDigit2 == 3 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 0:30:00
  198.             readyToPlaySound = false;
  199.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  200.                 soundSystem.PlayOneShot (thirty_Seconds);
  201.             } else {
  202.                 soundSystem.PlayOneShot (US_thirty_Seconds);
  203.             }
  204.             Invoke ("ResetReadyToPlaySound", 0.5f);
  205.         }
  206.         if (counterRunning && readyToPlaySound && timerDigit1 == 0 && timerDigit2 == 2 && timerDigit3 == 5 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 0:25:00
  207.             // play klaxon also at 25 sec marker
  208.             readyToPlaySound = false;
  209.             soundSystem.PlayOneShot (klaxon);
  210.             Invoke ("ResetReadyToPlaySound", 0.5f);
  211.         }
  212.         // 15 second marker
  213.         if (counterRunning && readyToPlaySound && timerDigit1 == 0 && timerDigit2 == 1 && timerDigit3 == 5 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 0:15:00
  214.             readyToPlaySound = false;
  215.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  216.                 soundSystem.PlayOneShot (fifteen_Seconds);
  217.             } else {
  218.                 soundSystem.PlayOneShot (US_fifteen_Seconds);
  219.             }
  220.             Invoke ("ResetReadyToPlaySound", 0.5f);
  221.         }
  222.         // 10 second marker
  223.         if (counterRunning && readyToPlaySound && timerDigit1 == 0 && timerDigit2 == 1 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 0:10:00
  224.             readyToPlaySound = false;
  225.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  226.                 soundSystem.PlayOneShot (ten_Seconds);
  227.             } else {
  228.                 soundSystem.PlayOneShot (US_ten_Seconds);
  229.             }
  230.             Invoke ("ResetReadyToPlaySound", 0.5f);
  231.         }
  232.         // 5 second marker
  233.         if (counterRunning && readyToPlaySound && timerDigit1 == 0 && timerDigit2 == 0 && timerDigit3 == 5 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 0:05:00
  234.             readyToPlaySound = false;
  235.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  236.                 soundSystem.PlayOneShot (five_Seconds);
  237.             } else {
  238.                 soundSystem.PlayOneShot (US_five_Seconds);
  239.             }
  240.             Invoke ("ResetReadyToPlaySound", 0.5f);
  241.         }
  242.         ///////////////////////
  243.         // INFO TEXT TIMINGS //
  244.         ///////////////////////
  245.         if (counterRunning && timerDigit1 == 3 && timerDigit2 == 5 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:50:00
  246.             // first info messages are played in BeginCountdown ()
  247.             if (readyToType) {
  248.                 TypeMessages ();
  249.             }
  250.         }
  251.         if (counterRunning && timerDigit1 == 3 && timerDigit2 == 4 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:40:00
  252.             if (readyToType) {
  253.                 TypeMessages ();
  254.             }
  255.         }
  256.         if (counterRunning && timerDigit1 == 3 && timerDigit2 == 3 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:30:00
  257.             if (readyToType) {
  258.                 TypeMessages ();
  259.             }
  260.         }
  261.         if (counterRunning && timerDigit1 == 3 && timerDigit2 == 2 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:20:00
  262.             if (readyToType) {
  263.                 TypeMessages ();
  264.             }
  265.         }
  266.         if (counterRunning && timerDigit1 == 3 && timerDigit2 == 1 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:10:00
  267.             if (readyToType) {
  268.                 TypeMessages ();
  269.             }
  270.         }
  271.         if (counterRunning && timerDigit1 == 3 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:00:00
  272.             if (readyToType) {
  273.                 TypeMessages ();
  274.             }
  275.         }
  276.         if (counterRunning && timerDigit1 == 2 && timerDigit2 == 5 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:50:00
  277.             if (readyToType) {
  278.                 TypeMessages ();
  279.             }
  280.         }
  281.         if (counterRunning && timerDigit1 == 2 && timerDigit2 == 4 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:40:00
  282.             if (readyToType) {
  283.                 TypeMessages ();
  284.             }
  285.         }
  286.         if (counterRunning && timerDigit1 == 2 && timerDigit2 == 3 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:30:00
  287.             if (readyToType) {
  288.                 TypeMessages ();
  289.             }
  290.         }
  291.         if (counterRunning && timerDigit1 == 2 && timerDigit2 == 2 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:20:00
  292.             if (readyToType) {
  293.                 TypeMessages ();
  294.             }
  295.         }
  296.         if (counterRunning && timerDigit1 == 2 && timerDigit2 == 1 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:10:00
  297.             if (readyToType) {
  298.                 TypeMessages ();
  299.             }
  300.         }
  301.         if (counterRunning && timerDigit1 == 2 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:00:00
  302.             if (readyToType) {
  303.                 TypeMessages ();
  304.             }
  305.         }
  306.     }
  307.  
  308.     void FixedUpdate ()
  309.     {
  310.         if (counterRunning) {
  311.             timerDigit5 -= Time.deltaTime * timerSpeed; // The timer engine on the last (sixth) digit * speed of countdown
  312.             digits [5].text = string.Format ("{0}", Mathf.Round (timerDigit5));
  313.             if (timerDigit0 < 0) {
  314.                 timerDigit0 = 9;
  315.             }
  316.             if (timerDigit1 < 0) {
  317.                 timerDigit1 = 9;
  318.             }
  319.             if (timerDigit2 < 0) {
  320.                 timerDigit2 = 5; // 5 here for the minutes reset
  321.                 timerDigit1 = timerDigit1 - 1;
  322.             }
  323.             if (timerDigit3 < 0) {
  324.                 timerDigit3 = 9;
  325.                 timerDigit2 = timerDigit2 - 1;
  326.             }
  327.             if (timerDigit4 < 0) {
  328.                 timerDigit4 = 9;
  329.                 timerDigit3 = timerDigit3 - 1;
  330.             }
  331.             if (timerDigit5 <= -0.3f) {
  332.                 UpdateDigits ();
  333.                 timerDigit5 = 9.5f; // we make it 9.5f here to compensate for the negative value of the last digit
  334.                 timerDigit4 = timerDigit4 - 1;
  335.             }
  336.         }
  337.     }
  338.  
  339.     void UpdateDigits ()
  340.     {
  341.         // the sixth digit is ommited here as its updated in FixedUpdate
  342.         digits [4].text = string.Format ("{0}", Mathf.Round (timerDigit4));
  343.         digits [3].text = string.Format ("{0}", Mathf.Round (timerDigit3));
  344.         digits [2].text = string.Format ("{0}", Mathf.Round (timerDigit2));
  345.         digits [1].text = string.Format ("{0}", Mathf.Round (timerDigit1));
  346.         digits [0].text = string.Format ("{0}", Mathf.Round (timerDigit0));
  347.         // STOP the timer at 000000
  348.         if (counterRunning && timerDigit0 == 0 && timerDigit1 == 0 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) {
  349.             counterRunning = false;
  350.             // blank out the numbers with zeros when count reaches zero
  351.             for (int blankOutDigit = 0; blankOutDigit < digits.Length; blankOutDigit++) {
  352.                 digits [blankOutDigit].text = "0";
  353.             }
  354.             // end the show
  355.             soundSystem.Stop (); // stop the counter sound
  356.             Invoke ("Ending", 1.0f); // slight delay before we start the ending sequence
  357.         }
  358.     }
  359.  
  360.     void Ending ()
  361.     {
  362.         if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  363.             uk_Backdrop.enabled = false; // turn off backdrops to end with
  364.         } else {
  365.             us_Backdrop.enabled = false;
  366.         }
  367.         // turn off counter digits
  368.         for (int disableDigit = 0; disableDigit < digits.Length; disableDigit++) {
  369.             digits [disableDigit].gameObject.SetActive (false);
  370.         }
  371.         // play the end movie(s)
  372.         if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  373.             info_Line1.GetComponent<Renderer> ().enabled = false; // turn off info text line 1
  374.             info_Line2.GetComponent<Renderer> ().enabled = false; // turn off info text line 2
  375.             end_Static.enabled = true; // we check Update() for end of video then quit
  376.         } else {
  377.             info_Line1USA.GetComponent<Renderer> ().enabled = false; // USA version
  378.             info_Line2USA.GetComponent<Renderer> ().enabled = false;
  379.             end_Static_USA.enabled = true;
  380.         }
  381.     }
  382.  
  383.     void BeginCountdown ()
  384.     {
  385.         if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  386.             breaking_News.enabled = false; // turn off UK Intro video
  387.             uk_Backdrop.enabled = true; // turn on backdrops
  388.             // turn digits on
  389.             for (int disableDigit = 0; disableDigit < digits.Length; disableDigit++) {
  390.                 digits [disableDigit].gameObject.SetActive (true);
  391.             }
  392.             counterRunning = true;
  393.             soundSystem.Play ();
  394.             info_Line1.GetComponent<Renderer> ().enabled = true;
  395.             info_Line2.GetComponent<Renderer> ().enabled = true;
  396.             Invoke ("TypeMessages", 3.0f);
  397.         } else { // USA
  398.             USA_Intro.enabled = false; // turn off US Intro video
  399.             us_Backdrop.enabled = true; // turn on backdrops
  400.             // turn digits on
  401.             for (int disableDigit = 0; disableDigit < digits.Length; disableDigit++) {
  402.                 digits [disableDigit].gameObject.SetActive (true);
  403.             }
  404.             // color the digits blue for the USA version
  405.             for (int colorDigit = 0; colorDigit < digits.Length; colorDigit++) {
  406.                 digits [colorDigit].color = new Color32 (0x25, 0x99, 0xD1, 0xFF); // RGBA
  407.             }
  408.             counterRunning = true;
  409.             soundSystem.Play ();
  410.             info_Line1USA.GetComponent<Renderer> ().enabled = true;
  411.             info_Line2USA.GetComponent<Renderer> ().enabled = true;
  412.             Invoke ("TypeMessages", 3.0f);
  413.         }
  414.     }
  415.  
  416.     IEnumerator Teletype ()
  417.     {
  418.         messageToType1 = teletypeMessages [messageMarker];
  419.         messageToType2 = teletypeMessages [messageMarker + 1];
  420.         foreach (char message in messageToType1.ToCharArray()) {
  421.             typeText1 += message;
  422.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  423.                 info_Line1.text = typeText1;
  424.             } else {
  425.                 info_Line1USA.text = typeText1;
  426.             }
  427.             yield return new WaitForSeconds (letterPause);
  428.         }
  429.         foreach (char message2 in messageToType2.ToCharArray()) {
  430.             typeText2 += message2;
  431.             if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
  432.                 info_Line2.text = typeText2;
  433.             } else {
  434.                 info_Line2USA.text = typeText2;
  435.             }
  436.             yield return new WaitForSeconds (letterPause);
  437.         }
  438.         typeText1 = "";
  439.         typeText2 = "";
  440.         messageMarker = messageMarker + 2;
  441.         readyToType = true;
  442.     }
  443.  
  444.     IEnumerator EndText ()
  445.     {
  446.         foreach (char endmessage in endText.ToCharArray()) {
  447.             typeEndText += endmessage;
  448.             ending_Text.text = typeEndText + "|";
  449.             yield return new WaitForSeconds (0.03f); // manual slower typing delay for dramatic effect
  450.         }
  451.         ending_Text.text = typeEndText; // here to remove the fake-cursor charecter when finished
  452.     }
  453.  
  454.     void TypeMessages ()
  455.     {
  456.         readyToType = false;
  457.         info_Line1.text = "";
  458.         info_Line2.text = "";
  459.         info_Line1USA.text = "";
  460.         info_Line2USA.text = "";
  461.         StartCoroutine (Teletype ());
  462.     }
  463.  
  464.     void StartEndText ()
  465.     {
  466.         ending_Text.text = ""; // clear the text mesh
  467.         ending_Text.GetComponent<Renderer> ().enabled = true; // turn on ending text line
  468.         StartCoroutine (EndText ());
  469.     }
  470.  
  471.     void ResetReadyToPlaySound ()
  472.     {
  473.         readyToPlaySound = true;
  474.     }
  475.  
  476.     void ReadEndingTextFile ()
  477.     {
  478.         try {
  479.             string userEndText = File.ReadAllText (@"C:\NUKE_PRANK\TextAtEnd.txt");
  480.             if (userEndText.Length > 0) {
  481.                 endText = userEndText;
  482.                 return;
  483.             }
  484.         } catch (IOException) { // if we failed to read a text file insert the default text below
  485.             endText = "SKYNET SYSTEM INITIALIZED - STAND BY";
  486.             return;
  487.         }
  488.     }
  489.  
  490.     void Quit ()
  491.     {
  492.         Application.Quit ();
  493.     }
  494. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement