PieManager.cs 1.64 KB
Newer Older
1
2
3
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
4
5
using UnityEngine.UI;
using UnityEngine.SceneManagement;
6
7
8

public class PieManager : MonoBehaviour {

9
    public static int pieCount;
10
11
    public static bool pieInScene = false;
    public static bool start = true;
12
    public static int numTargets;
13
14
15
16
17
    public Text exitText;
    public Text exitTimer;

    private bool gameOver;
    private float exitTime;
18

19
20
    private void Update()
    {
astatham's avatar
astatham committed
21
        if(pieCount == 0){
22
23
24
25
26
27
28
29
30
31
32
33
            if (!gameOver) {
                gameOver = true;
                exitTime = Time.time + 5;
                exitText.gameObject.SetActive(true);
            }
        }
        if (gameOver) {
            if (Time.time > exitTime) {
                SceneManager.LoadScene("Daytime");
            } else {
                exitTimer.text = ((int)(exitTime - Time.time + 0.98f)).ToString();
            }
34
35
36
37
38
        }
    }

    void Start()
    {
39
40
41
        exitText.gameObject.SetActive(false);
        exitTime = Mathf.Infinity;

42
        numTargets = Random.Range(1, 9);
43
44
        pieCount = numTargets * 2;
        PieTarget[] targets = FindObjectsOfType<PieTarget>();
45
46
        for (int i = 0; i < 9 - numTargets; i++)
        {
47
48
49
50
51
52
            int n;
            do
            {
                n = Random.Range(0, 9);
            } while (targets[n].transform.parent.gameObject.activeSelf == false);
            targets[n].transform.parent.gameObject.SetActive(false);
53
        }
astatham's avatar
astatham committed
54
55
        targets[4].gameObject.SetActive(true);
        //gameObject.transform.GetComponent<MovingTarget>().gameObject.SetActive(true);
56
57
    }
}