Dialogue System
Clock System
Developed by Tyler Sweppenhiser and Shane Tupler for "4AM"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueSystem : MonoBehaviour
{
private GameObject canvas;
public GameObject E;
public string Name;
[TextArea(3, 10)]
public string[] sentences;
public Text Dialogue;
public Text NameText;
private int sentencesLeft;
private int currentSentence = 0;
private bool canDialogue = false;
public float typingSpeed;
void Awake()
{
Dialogue = GameObject.FindGameObjectWithTag("DialogueText").GetComponent<Text>();
NameText = GameObject.FindGameObjectWithTag("NameText").GetComponent<Text>();
E = GameObject.FindGameObjectWithTag("ESprite");
if (NameText != null)
{
NameText.text = Name;
}
sentencesLeft = sentences.Length;
canvas = GameObject.FindGameObjectWithTag("DialogueCanvas");
E.SetActive(false);
}
void Update()
{
if (canDialogue == true)
{
if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.Return))
{
canvas.SetActive(true);
AttemptDialogue();
}
}
}
public void AttemptDialogue()
{
if (sentencesLeft > 0)
{
if (currentSentence == 0)
{
NextDialogue();
}
else if (Dialogue.text == sentences[currentSentence -1])
{
NextDialogue();
}
}
else if (Dialogue.text == sentences[currentSentence - 1])
{
canvas.SetActive(false);
E.SetActive(false);
}
}
public void NextDialogue()
{
E.SetActive(false);
Dialogue.text = "";
StartCoroutine(Type());
sentencesLeft -= 1;
currentSentence += 1;
}
IEnumerator Type()
{
foreach(char letter in sentences[currentSentence].ToCharArray())
{
Dialogue.text += letter;
yield return new WaitForSeconds(typingSpeed);
}
}
void OnTriggerEnter2D()
{
if (sentencesLeft > 0)
{
canDialogue = true;
if (currentSentence == 0)
{
E.SetActive(true);
}
}
else
{
canvas.SetActive(false);
E.SetActive(false);
}
}
void OnTriggerExit2D()
{
canDialogue = false;
E.SetActive(false);
}
}
Developed by Tyler Sweppenhiser "4AM"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Clock : MonoBehaviour
{
public Text hour;
// Start is called before the first frame update
void Start()
{
Invoke("Set11", 30f);
Invoke("Set12", 60f);
Invoke("Set1", 90f);
Invoke("Set2", 120f);
Invoke("Set3", 150f);
Invoke("Set4", 180f);
hour = GetComponent<Text>();
hour.text = "10:00PM";
}
// sets the time to 11PM
void Set11()
{
hour.text = "11:00PM";
}
void Set12()
{
hour.text = "12:00AM";
}
// sets the time to 11PM
void Set1()
{
hour.text = "1:00AM";
}
// sets the time to 11PM
void Set2()
{
hour.text = "2:00AM";
}
// sets the time to 11PM
void Set3()
{
hour.text = "3:00AM";
}
// sets the time to 11PM
void Set4()
{
hour.text = "4:00AM";
}
}
Fill Bar Mechanics #1
Score System
Developed by Tyler Sweppenhiser for "4AM"
​
using UnityEngine;
using UnityEngine.UI;
public class DangerBar : MonoBehaviour
{
// Unity UI References
public Slider slider;
// Slider's value
public float currentValue = 0f;
public float currentValueChange = 0f;
public float countdown = 40f;
void Start()
{
slider = GameObject.FindGameObjectWithTag("DangerSlider").GetComponent<Slider>();
}
void Update()
{
slider.value = currentValue;
countdown -= Time.deltaTime;
if (countdown <= 0)
{
Change(+.1f);
countdown = 40f;
}
if (currentValue < 0)
{
currentValue = 0;
}
if (currentValue > 1)
{
currentValue = 1;
}
if (currentValue <= currentValueChange)
{
currentValue += 0.0001f;
}
if (currentValue >= currentValueChange)
{
currentValue -= 0.0001f;
}
}
public void Change(float changeAmt)
{
currentValueChange += changeAmt;
}
}
​
​
Developed by Tyler Sweppenhiser and Shane Tupler for "Digital Janitor"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class ScoreScript : MonoBehaviour{
public string sceneName;
public Text ScoreText;
public Text CorrectText;
public Text MistakesText;
public Text RoundText;
public int ScoreValue = 0;
public int MalwareRecycledScore;
public int MalwareSecuredScore;
public int PersonalFoldersSecuredScore;
public int PersonalFoldersRecycledScore;
public int CorrectSorts;
public int MistakesMade;
public int RoundCountScore;
void Update()
{
DontDestroyOnLoad(gameObject);
sceneName = SceneManager.GetActiveScene().name;
if (sceneName == "MainScene")
{
// Saves variable data from various scripts in this script
MalwareRecycledScore = Recycle.MalwareRecycled;
MalwareSecuredScore = SecureDrive.MalwareSecured;
PersonalFoldersSecuredScore = SecureDrive.PersonalFilesSecured;
PersonalFoldersRecycledScore = Recycle.PersonalFoldersRecycle;
RoundCountScore = SpawnFolders.waveCount;
}
if (sceneName == "Final")
{
CalculateScore();
}
}
void CalculateScore()
{
ScoreText = GameObject.FindGameObjectWithTag("Score").GetComponent<Text>();
CorrectText = GameObject.FindGameObjectWithTag("Correct").GetComponent<Text>();
MistakesText = GameObject.FindGameObjectWithTag("Mistakes").GetComponent<Text>();
RoundText = GameObject.FindGameObjectWithTag("Round").GetComponent<Text>();
// Calculates and displays the score
ScoreValue = (MalwareRecycledScore * 100) + (PersonalFoldersSecuredScore * 100) - (MalwareSecuredScore * 150) - (PersonalFoldersRecycledScore * 150);
ScoreText.text = " Score: " + ScoreValue;
// Calculates and displays the number of correct sorts
CorrectSorts = MalwareRecycledScore + PersonalFoldersSecuredScore;
CorrectText.text = "Files Sorted Correctly: " + CorrectSorts;
// Calculates and displays the number of mistakes made
MistakesMade = MalwareSecuredScore + PersonalFoldersRecycledScore;
MistakesText.text = "Files Sorted Incorrectly: " + MistakesMade;
// Displays the number of waves lasted
RoundText.text = "Waves Lasted: " + RoundCountScore;
Destroy(gameObject);
}
}
Fill Bar Mechanics #2
Play Game Script
Developed by Tyler Sweppenhiser for "4AM"
​
using UnityEngine;
using UnityEngine.UI;
public class RadialFill : MonoBehaviour
{
public Image fillImage;
public Text displayText;
protected float maxValue = 1f, minValue = 0f;
public static float currentValueR = 1f;
public float currentValueReference;
void Start()
{
currentValueR = 0f;
}
void Update()
{
float fillPercentage = currentValueR / maxValue;
fillImage.fillAmount = fillPercentage;
displayText.text = (fillPercentage * 100).ToString("0.00") + "%";
if (currentValueR < 0)
{
currentValueR = 0;
}
if (currentValueR > 1)
{
currentValueR = 1;
}
currentValueReference = currentValueR;
}
}
​
Developed by Tyler Sweppenhiser for "Digital Janitor"
​
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayBack : MonoBehaviour
{
public static bool isMouseOver = false;
public void PlayGame()
{
isMouseOver = false;
SceneManager.LoadScene("MainScene");
}
void OnMouseOver()
{
isMouseOver = true;
}
void OnMouseExit()
{
isMouseOver = false;
}
}