Commit 46ef8b95 authored by astatham's avatar astatham
Browse files

Pie Throwing records score and exits when all targets have been hit

parent 3c16b3b0
......@@ -13,14 +13,19 @@ public class MovingTarget : MonoBehaviour {
previousPos = -9f;
if (gameObject.activeSelf){
PieTarget[] targets = gameObject.transform.parent.GetComponentsInChildren<PieTarget>();
print(targets.Length);
for (int i = 0; i < targets.Length; i++)
{
targets[i].gameObject.SetActive(false);
if (targets[i].gameObject.activeSelf)
{
targets[i].gameObject.SetActive(false);
PieManager.numTargets--;
}
//targets[i].gameObject.transform.GetChild(0).gameObject.SetActive(false);
}
}
gameObject.SetActive(true);
PieManager.numTargets++;
//gameObject.transform.GetChild(0).gameObject.SetActive(true);
}
// Update is called once per frame
......
......@@ -6,7 +6,7 @@ using UnityEngine.SceneManagement;
public class PieManager : MonoBehaviour {
public static int pieCount;
public static int pieCount, score;
public static bool pieInScene = false;
public static bool start = true;
public static int numTargets;
......@@ -18,7 +18,7 @@ public class PieManager : MonoBehaviour {
private void Update()
{
if(pieCount == 0){
if(pieCount == 0 || numTargets == 0){
if (!gameOver) {
gameOver = true;
exitTime = Time.time + 5;
......@@ -26,7 +26,9 @@ public class PieManager : MonoBehaviour {
}
}
if (gameOver) {
if (Time.time > exitTime) {
if (Time.time > exitTime)
{
print(score);
SceneManager.LoadScene("Daytime");
} else {
exitTimer.text = ((int)(exitTime - Time.time + 0.98f)).ToString();
......@@ -42,7 +44,7 @@ public class PieManager : MonoBehaviour {
numTargets = Random.Range(1, 9);
pieCount = numTargets * 2;
PieTarget[] targets = FindObjectsOfType<PieTarget>();
for (int i = 0; i < 9 - numTargets; i++)
for (int i = 0; i < 10 - numTargets; i++)
{
int n;
do
......
......@@ -8,8 +8,16 @@ public class PieTarget : MonoBehaviour {
private void OnTriggerEnter2D(Collider2D collision)
{
if (gameObject.GetComponent<MovingTarget>())
{
PieManager.score += 200;
}
else
{
PieManager.score += 100;
}
PieManager.numTargets--;
Destroy(gameObject);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment