aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/LevelController.cs
blob: d79bc3bbcc343ca47e7f05ff06a55b5b81d3cd02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelController : MonoBehaviour
{
    [SerializeField] GameObject treasure;
    [SerializeField] List<GameObject> enemies;

    private string clone = "(Clone)";

    public void StartGame()
    {
        SceneManager.LoadScene("Jungle");
    }

    public void QuitGame()
    {
        Application.Quit();
    }


    public static void LoadMenu()
    {
        SceneManager.LoadScene("Start Scene");
    }

    public void ResetLevel()
    {
        //Destroy
        Destroy(GameObject.Find("Boulder(Clone)"));
        Destroy(GameObject.Find("BoobyTrapSpawnPoint(Clone)"));
        CloneDestroy("Treasure");
        DestroyList(enemies);

        //Instantiate
        Instantiate(treasure);
        InstantiateList(enemies);
    }

    private void CloneDestroy(string objectName)
    {
        var obj = GameObject.Find(objectName);
        if (obj)
            Destroy(obj);
        else
        {
            obj = GameObject.Find(objectName + clone);
            if (obj)
                Destroy(GameObject.Find(objectName + clone));
        }
    }

    private void DestroyList(List<GameObject> gameObjects)
    {
        foreach(GameObject obj in gameObjects)
        {
            CloneDestroy(obj.name);
        }
    }

    private void InstantiateList(List<GameObject> gameObjects)
    {
        foreach (GameObject obj in gameObjects)
        {
            Instantiate(obj);
        }
    }
}