-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished Scripts for Game jam submission
The coding is a bit messy on account of limited time... But it works well!
- Loading branch information
Showing
9 changed files
with
442 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using System; | ||
|
||
public class Countdown : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
private RawImage refImage; | ||
[SerializeField] | ||
private GameObject finishText; | ||
|
||
[SerializeField] | ||
private GameObject tryAgainButton; | ||
[SerializeField] | ||
private GameObject quitButton; | ||
|
||
private Vector2 refImagePos; | ||
private Vector2 cornerPos; | ||
[SerializeField] | ||
private GameObject countdownText; | ||
|
||
|
||
private bool movedToCorner = false; | ||
private bool cornerWaitTime = false; | ||
private bool doneMoving = false; | ||
private bool counting = false; | ||
private float countdownTime = 45.0f; | ||
|
||
private Action startTimerListener; | ||
|
||
// Use this for initialization | ||
void Start() | ||
{ | ||
cornerPos = new Vector2(-152.0f, -100.0f); | ||
startTimerListener = new Action(() => { StartCoroutine(CountStart()); }); | ||
EventManager.StartListening("StartTimer", startTimerListener); | ||
StartCoroutine(ShowRefImage()); | ||
} | ||
|
||
IEnumerator ShowRefImage() | ||
{ | ||
yield return new WaitForSeconds(0.25f); | ||
refImage.texture = PositionComparison.refImage; | ||
refImage.gameObject.SetActive(true); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
if (!movedToCorner) | ||
{ | ||
StartCoroutine(MoveToCorner()); | ||
movedToCorner = true; | ||
} | ||
|
||
if (cornerWaitTime) | ||
{ | ||
refImage.rectTransform.anchorMax = new Vector2(1.0f, 1.0f); | ||
refImage.rectTransform.anchorMin = new Vector2(1.0f, 1.0f); | ||
refImage.rectTransform.anchoredPosition = cornerPos; | ||
EventManager.TriggerEvent("StartTimer"); | ||
EventManager.TriggerEvent("ToggleControls"); | ||
} | ||
if (counting) | ||
{ | ||
countdownTime -= Time.deltaTime; | ||
countdownText.GetComponent<Text>().text = Mathf.FloorToInt(countdownTime).ToString(); | ||
} | ||
|
||
|
||
if(countdownTime < 0.2 && countdownTime != -1) | ||
{ | ||
EventManager.TriggerEvent("DisableControls"); | ||
countdownTime = -1; | ||
counting = false; | ||
EventManager.TriggerEvent("Finish"); | ||
countdownText.SetActive(false); | ||
StartCoroutine(Finish()); | ||
return; | ||
} | ||
|
||
} | ||
|
||
IEnumerator Finish() | ||
{ | ||
finishText.SetActive(true); | ||
yield return new WaitForSeconds(3.0f); | ||
Text finishTextComp = finishText.GetComponent<Text>(); | ||
if (PositionComparison.scoreFinal < 35) | ||
finishTextComp.color = new Color(255, 0, 0); | ||
else if (PositionComparison.scoreFinal > 35 && PositionComparison.scoreFinal < 75) | ||
{ | ||
finishTextComp.color = new Color(255.0f, 255.0f, 0); | ||
} | ||
else | ||
{ | ||
finishTextComp.color = new Color(0, 255, 0); | ||
} | ||
finishText.GetComponent<Text>().text = "Your Score: " + PositionComparison.scoreFinal.ToString(); | ||
|
||
yield return new WaitForSeconds(4.0f); | ||
quitButton.SetActive(true); | ||
tryAgainButton.SetActive(true); | ||
|
||
} | ||
|
||
IEnumerator MoveToCorner() | ||
{ | ||
yield return new WaitForSeconds(3.0f); | ||
cornerWaitTime = true; | ||
} | ||
|
||
IEnumerator CountStart() | ||
{ | ||
countdownText.GetComponent<Text>().text = "GO!"; | ||
EventManager.TriggerEvent("EnableControls"); | ||
yield return new WaitForSeconds(1.0f); | ||
counting = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
using UnityEngine.UI; | ||
|
||
public class GameUI : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
private GameObject resumeButton; | ||
[SerializeField] | ||
private GameObject pauseText; | ||
[SerializeField] | ||
private GameObject quitButton; | ||
|
||
public void TryAgainClick() | ||
{ | ||
SceneManager.LoadScene(1); | ||
} | ||
|
||
public void ResumeClick() | ||
{ | ||
Time.timeScale = 1.0f; | ||
EventManager.TriggerEvent("EnableControls"); | ||
resumeButton.SetActive(false); | ||
pauseText.SetActive(false); | ||
quitButton.SetActive(false); | ||
|
||
|
||
} | ||
|
||
public void QuitClick() | ||
{ | ||
Application.Quit(); | ||
} | ||
|
||
public void Update() | ||
{ | ||
if (Input.GetKeyDown(KeyCode.Escape) && Time.timeScale == 1.0f) | ||
{ | ||
Time.timeScale = 0.0f; | ||
EventManager.TriggerEvent("DisableControls"); | ||
resumeButton.SetActive(true); | ||
pauseText.SetActive(true); | ||
quitButton.SetActive(true); | ||
} | ||
else if (Input.GetKeyDown(KeyCode.Escape) && Time.timeScale == 0.0f) | ||
{ | ||
Time.timeScale = 1.0f; | ||
EventManager.TriggerEvent("EnableControls"); | ||
resumeButton.SetActive(false); | ||
pauseText.SetActive(false); | ||
quitButton.SetActive(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.