]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Mouse/Reset.cs
checkpoint-system v0.3
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Mouse / Reset.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.SceneManagement;
5
6 public class Reset : MonoBehaviour
7 {
8     private CheckpointManager checkpointManager;
9
10     private CheeseCollection cheeseCollection;
11
12     public GameObject cheeseCoin;
13
14     Abyss abyss;
15
16     Health health;
17
18     void Start()
19     {
20         checkpointManager = GameObject.FindGameObjectWithTag("CheckpointManager").GetComponent<CheckpointManager>();
21         abyss = GetComponent<Abyss>();
22         health = GetComponent<Health>();
23         cheeseCollection = GetComponent<CheeseCollection>();
24     }
25
26     void ResetPosition()
27     {
28         transform.position = checkpointManager.lastCheckpointPos;
29         cheeseCollection.cheesecount = checkpointManager.lastCheeseCount;
30         cheeseCollection.countText.text = cheeseCollection.cheesecount.ToString();
31         if (checkpointManager.isCheeseCoinCollected)
32         {
33             cheeseCoin.SetActive(false);
34         }
35         abyss.fallenDown = false;
36         health.mouseHealth = 5;
37     }
38
39     void Update()
40     {
41         if(abyss.fallenDown || health.mouseHealth <= 0)
42         {
43             ResetPosition();
44         }
45     }
46 }