Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.Video;
- using System.IO;
- /**
- * US/UK NUCLEAR-STRIKE VIDEO PRANK
- * DEVELOPER NOTES : Anthony Smith 20/03/2018
- * COMPLETED SCRIPT 29/03/2018 - 00:33
- * ==========================================
- * Note: Nuclear warning prank with video for UK and the USA
- * TO-DO : nothing.
- *
- **/
- public class NukeTimer : MonoBehaviour
- {
- public TextMesh[] digits;
- public AudioClip siren, intro_Speech, three_Minutes, two_Minutes, one_Minute, thirty_Seconds, fifteen_Seconds, ten_Seconds;
- public AudioClip five_Seconds, klaxon, no_Test, attention, EAS_Sound;
- 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;
- public SpriteRenderer uk_Backdrop, us_Backdrop;
- public VideoPlayer breaking_News, end_Static, end_Static_USA, USA_Intro;
- private int timerDigit0 = 0, timerDigit1 = 4, timerDigit2 = 0, timerDigit3 = 0, timerDigit4 = 0, messageMarker = 0;
- // default clock starts with 040000 (four minute countdown)
- private float timerDigit5 = 0f, timerSpeed = 100f, letterPause = 0.01f;
- private AudioSource soundSystem;
- public TextMesh info_Line1, info_Line2, info_Line1USA, info_Line2USA, ending_Text;
- private string messageToType1, messageToType2;
- private string infoMessage1, infoMessage2;
- private string typeText1, typeText2, typeEndText, endText;
- private bool readyToType = true, readyToPlaySound = true, counterRunning;
- string[] teletypeMessages = {
- "We shall be on the air every hour, on the hour, stay tuned to this channel.",
- "The 'all clear' message will also be given on this channel.",
- "Radioactive fall-out which follows a nuclear explosion is many times more dangerous,",
- "Especially if you are directly exposed to it in the open.",
- "Roofs and walls offer substantial protection. The safest place is indoors.",
- "Make sure gas and other fuel supplies are turned off and that all fires are extinguished.",
- "If mains water is available, this can be used for fire-fighting.",
- "The mains water supply may not be available for very long.",
- "You should also refill all your containers for drinking water after the fires have been put out,",
- "Water must not be used for flushing lavatories.",
- "Use your water only for essential drinking and cooking purposes.",
- "Water means life, Don't waste it.",
- "Make your food stocks last, ration your supply, because it may have to last for 14 days or more.",
- "If you have fresh food in the house, use this first to avoid wasting it, food in tins will keep.",
- "If you live in an area where a fall out warning has been given,",
- "Stay in your fall-out room until you are told it is safe to come out.",
- "When the immediate danger has passed the sirens will sound a steady note.",
- "The 'all clear' message will also be given on this channel.",
- "If you leave the fall-out room to go to the lavatory or replenish food or water supplies,",
- "Do NOT remain outside the room for a minute longer than is necessary.",
- "Do NOT in any circumstances go outside the house, radioactive fall-out can KILL.",
- "You cannot see it or feel it, but it is there.",
- "Stay in your fall-out room until you hear the 'all clear' on the sirens.",
- "If you go outside, you will bring danger to your family and you may die.",
- "We shall be on the air every hour, on the hour, stay tuned to this channel.",
- "Find shelter NOW."
- };
- void Start ()
- {
- Cursor.visible = false;
- // turn digits off to start
- for (int disableDigit = 0; disableDigit < digits.Length; disableDigit++) {
- digits [disableDigit].gameObject.SetActive (false);
- }
- info_Line1.GetComponent<Renderer> ().enabled = false; // turn off info text line 1 to start
- info_Line2.GetComponent<Renderer> ().enabled = false; // turn off info text line 2 to start
- info_Line1USA.GetComponent<Renderer> ().enabled = false; // USA version
- info_Line2USA.GetComponent<Renderer> ().enabled = false; // USA version
- ending_Text.GetComponent<Renderer> ().enabled = false; // turn off ending text line
- if (PlayerPrefs.HasKey ("whichcountry")) { // check if user changed country
- } else {
- PlayerPrefs.SetInt ("whichcountry", 0); // country code, 0 for UK, 1 for USA - default UK
- }
- uk_Backdrop.enabled = false; // turn off backdrops to start
- us_Backdrop.enabled = false;
- counterRunning = false; // stopped here, wait for intro video to finish first
- // Sound initialization
- soundSystem = gameObject.GetComponent<AudioSource> ();
- soundSystem.Stop (); // pause counter sound at start
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- breaking_News.enabled = true; // start the UK intro
- } else {
- USA_Intro.enabled = true; // start the USA intro
- }
- ReadEndingTextFile (); // the ending line of text a user can change
- // Initialize the timer digits
- digits [5].text = string.Format ("{0}", Mathf.Round (timerDigit5));
- digits [4].text = string.Format ("{0}", Mathf.Round (timerDigit4));
- digits [3].text = string.Format ("{0}", Mathf.Round (timerDigit3));
- digits [2].text = string.Format ("{0}", Mathf.Round (timerDigit2));
- digits [1].text = string.Format ("{0}", Mathf.Round (timerDigit1));
- digits [0].text = string.Format ("{0}", Mathf.Round (timerDigit0));
- }
- void Update ()
- {
- if (breaking_News.isActiveAndEnabled && breaking_News.frame == 1760) { // video has stopped playing (newsbreaking video has 1761 frames)
- BeginCountdown ();
- }
- if (USA_Intro.isActiveAndEnabled && USA_Intro.frame == 843) { // video has stopped playing (US Intro video has 844 frames)
- BeginCountdown ();
- }
- // end of UK static video with end text start-up
- if (end_Static.isActiveAndEnabled && end_Static.frame >= 422) { // video has stopped playing (end_static video has 422 frames)
- end_Static.enabled = false; // disable the static
- Invoke ("StartEndText", 1.0f); // slight delay before we show the ending text
- Invoke ("Quit", 11.0f); // quit after ten seconds or so...
- }
- // end of US static video
- if (end_Static_USA.isActiveAndEnabled && end_Static_USA.frame >= 423) { // video has stopped playing (end_static USA video has 424 frames)
- end_Static_USA.enabled = false; // disable the US static
- Invoke ("StartEndText", 1.0f); // slight delay before we show the ending text
- Invoke ("Quit", 11.0f); // quit after ten seconds or so...
- }
- // check time(s) and play SOUNDS
- if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 5 && timerDigit3 == 9 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:59:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 1) { // USA
- soundSystem.PlayOneShot (EAS_Sound); // play the EAS system tone on start-up
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 5 && timerDigit3 == 8 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:58:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (attention);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 5 && timerDigit3 == 4 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:55:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (intro_Speech);
- } else {
- soundSystem.PlayOneShot (US_Speech);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 2 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:20:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (no_Test);
- } else {
- soundSystem.PlayOneShot (US_no_Test);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 1 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:10:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (no_Test);
- } else {
- soundSystem.PlayOneShot (US_no_Test);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- if (counterRunning && readyToPlaySound && timerDigit1 == 2 && timerDigit2 == 5 && timerDigit3 == 8 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:58:00
- readyToPlaySound = false;
- soundSystem.PlayOneShot (siren);
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- // 3 minute marker
- if (counterRunning && readyToPlaySound && timerDigit1 == 3 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:00:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (three_Minutes);
- } else {
- soundSystem.PlayOneShot (US_three_Minutes);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- // 2 minute marker
- if (counterRunning && readyToPlaySound && timerDigit1 == 2 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:00:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (two_Minutes);
- } else {
- soundSystem.PlayOneShot (US_two_Minutes);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- // 1 minute marker
- if (counterRunning && readyToPlaySound && timerDigit1 == 1 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:00:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (one_Minute);
- } else {
- soundSystem.PlayOneShot (US_one_Minute);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- // 30 second marker
- if (counterRunning && readyToPlaySound && timerDigit1 == 0 && timerDigit2 == 3 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 0:30:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (thirty_Seconds);
- } else {
- soundSystem.PlayOneShot (US_thirty_Seconds);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- if (counterRunning && readyToPlaySound && timerDigit1 == 0 && timerDigit2 == 2 && timerDigit3 == 5 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 0:25:00
- // play klaxon also at 25 sec marker
- readyToPlaySound = false;
- soundSystem.PlayOneShot (klaxon);
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- // 15 second marker
- if (counterRunning && readyToPlaySound && timerDigit1 == 0 && timerDigit2 == 1 && timerDigit3 == 5 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 0:15:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (fifteen_Seconds);
- } else {
- soundSystem.PlayOneShot (US_fifteen_Seconds);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- // 10 second marker
- if (counterRunning && readyToPlaySound && timerDigit1 == 0 && timerDigit2 == 1 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 0:10:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (ten_Seconds);
- } else {
- soundSystem.PlayOneShot (US_ten_Seconds);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- // 5 second marker
- if (counterRunning && readyToPlaySound && timerDigit1 == 0 && timerDigit2 == 0 && timerDigit3 == 5 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 0:05:00
- readyToPlaySound = false;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- soundSystem.PlayOneShot (five_Seconds);
- } else {
- soundSystem.PlayOneShot (US_five_Seconds);
- }
- Invoke ("ResetReadyToPlaySound", 0.5f);
- }
- ///////////////////////
- // INFO TEXT TIMINGS //
- ///////////////////////
- if (counterRunning && timerDigit1 == 3 && timerDigit2 == 5 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:50:00
- // first info messages are played in BeginCountdown ()
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 3 && timerDigit2 == 4 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:40:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 3 && timerDigit2 == 3 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:30:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 3 && timerDigit2 == 2 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:20:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 3 && timerDigit2 == 1 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:10:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 3 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 3:00:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 2 && timerDigit2 == 5 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:50:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 2 && timerDigit2 == 4 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:40:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 2 && timerDigit2 == 3 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:30:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 2 && timerDigit2 == 2 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:20:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 2 && timerDigit2 == 1 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:10:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- if (counterRunning && timerDigit1 == 2 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) { // call at 2:00:00
- if (readyToType) {
- TypeMessages ();
- }
- }
- }
- void FixedUpdate ()
- {
- if (counterRunning) {
- timerDigit5 -= Time.deltaTime * timerSpeed; // The timer engine on the last (sixth) digit * speed of countdown
- digits [5].text = string.Format ("{0}", Mathf.Round (timerDigit5));
- if (timerDigit0 < 0) {
- timerDigit0 = 9;
- }
- if (timerDigit1 < 0) {
- timerDigit1 = 9;
- }
- if (timerDigit2 < 0) {
- timerDigit2 = 5; // 5 here for the minutes reset
- timerDigit1 = timerDigit1 - 1;
- }
- if (timerDigit3 < 0) {
- timerDigit3 = 9;
- timerDigit2 = timerDigit2 - 1;
- }
- if (timerDigit4 < 0) {
- timerDigit4 = 9;
- timerDigit3 = timerDigit3 - 1;
- }
- if (timerDigit5 <= -0.3f) {
- UpdateDigits ();
- timerDigit5 = 9.5f; // we make it 9.5f here to compensate for the negative value of the last digit
- timerDigit4 = timerDigit4 - 1;
- }
- }
- }
- void UpdateDigits ()
- {
- // the sixth digit is ommited here as its updated in FixedUpdate
- digits [4].text = string.Format ("{0}", Mathf.Round (timerDigit4));
- digits [3].text = string.Format ("{0}", Mathf.Round (timerDigit3));
- digits [2].text = string.Format ("{0}", Mathf.Round (timerDigit2));
- digits [1].text = string.Format ("{0}", Mathf.Round (timerDigit1));
- digits [0].text = string.Format ("{0}", Mathf.Round (timerDigit0));
- // STOP the timer at 000000
- if (counterRunning && timerDigit0 == 0 && timerDigit1 == 0 && timerDigit2 == 0 && timerDigit3 == 0 && timerDigit4 == 0 && timerDigit5 < 2) {
- counterRunning = false;
- // blank out the numbers with zeros when count reaches zero
- for (int blankOutDigit = 0; blankOutDigit < digits.Length; blankOutDigit++) {
- digits [blankOutDigit].text = "0";
- }
- // end the show
- soundSystem.Stop (); // stop the counter sound
- Invoke ("Ending", 1.0f); // slight delay before we start the ending sequence
- }
- }
- void Ending ()
- {
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- uk_Backdrop.enabled = false; // turn off backdrops to end with
- } else {
- us_Backdrop.enabled = false;
- }
- // turn off counter digits
- for (int disableDigit = 0; disableDigit < digits.Length; disableDigit++) {
- digits [disableDigit].gameObject.SetActive (false);
- }
- // play the end movie(s)
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- info_Line1.GetComponent<Renderer> ().enabled = false; // turn off info text line 1
- info_Line2.GetComponent<Renderer> ().enabled = false; // turn off info text line 2
- end_Static.enabled = true; // we check Update() for end of video then quit
- } else {
- info_Line1USA.GetComponent<Renderer> ().enabled = false; // USA version
- info_Line2USA.GetComponent<Renderer> ().enabled = false;
- end_Static_USA.enabled = true;
- }
- }
- void BeginCountdown ()
- {
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- breaking_News.enabled = false; // turn off UK Intro video
- uk_Backdrop.enabled = true; // turn on backdrops
- // turn digits on
- for (int disableDigit = 0; disableDigit < digits.Length; disableDigit++) {
- digits [disableDigit].gameObject.SetActive (true);
- }
- counterRunning = true;
- soundSystem.Play ();
- info_Line1.GetComponent<Renderer> ().enabled = true;
- info_Line2.GetComponent<Renderer> ().enabled = true;
- Invoke ("TypeMessages", 3.0f);
- } else { // USA
- USA_Intro.enabled = false; // turn off US Intro video
- us_Backdrop.enabled = true; // turn on backdrops
- // turn digits on
- for (int disableDigit = 0; disableDigit < digits.Length; disableDigit++) {
- digits [disableDigit].gameObject.SetActive (true);
- }
- // color the digits blue for the USA version
- for (int colorDigit = 0; colorDigit < digits.Length; colorDigit++) {
- digits [colorDigit].color = new Color32 (0x25, 0x99, 0xD1, 0xFF); // RGBA
- }
- counterRunning = true;
- soundSystem.Play ();
- info_Line1USA.GetComponent<Renderer> ().enabled = true;
- info_Line2USA.GetComponent<Renderer> ().enabled = true;
- Invoke ("TypeMessages", 3.0f);
- }
- }
- IEnumerator Teletype ()
- {
- messageToType1 = teletypeMessages [messageMarker];
- messageToType2 = teletypeMessages [messageMarker + 1];
- foreach (char message in messageToType1.ToCharArray()) {
- typeText1 += message;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- info_Line1.text = typeText1;
- } else {
- info_Line1USA.text = typeText1;
- }
- yield return new WaitForSeconds (letterPause);
- }
- foreach (char message2 in messageToType2.ToCharArray()) {
- typeText2 += message2;
- if (PlayerPrefs.GetInt ("whichcountry") == 0) { // UK
- info_Line2.text = typeText2;
- } else {
- info_Line2USA.text = typeText2;
- }
- yield return new WaitForSeconds (letterPause);
- }
- typeText1 = "";
- typeText2 = "";
- messageMarker = messageMarker + 2;
- readyToType = true;
- }
- IEnumerator EndText ()
- {
- foreach (char endmessage in endText.ToCharArray()) {
- typeEndText += endmessage;
- ending_Text.text = typeEndText + "|";
- yield return new WaitForSeconds (0.03f); // manual slower typing delay for dramatic effect
- }
- ending_Text.text = typeEndText; // here to remove the fake-cursor charecter when finished
- }
- void TypeMessages ()
- {
- readyToType = false;
- info_Line1.text = "";
- info_Line2.text = "";
- info_Line1USA.text = "";
- info_Line2USA.text = "";
- StartCoroutine (Teletype ());
- }
- void StartEndText ()
- {
- ending_Text.text = ""; // clear the text mesh
- ending_Text.GetComponent<Renderer> ().enabled = true; // turn on ending text line
- StartCoroutine (EndText ());
- }
- void ResetReadyToPlaySound ()
- {
- readyToPlaySound = true;
- }
- void ReadEndingTextFile ()
- {
- try {
- string userEndText = File.ReadAllText (@"C:\NUKE_PRANK\TextAtEnd.txt");
- if (userEndText.Length > 0) {
- endText = userEndText;
- return;
- }
- } catch (IOException) { // if we failed to read a text file insert the default text below
- endText = "SKYNET SYSTEM INITIALIZED - STAND BY";
- return;
- }
- }
- void Quit ()
- {
- Application.Quit ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement