]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Maus/Checkpoint.cs
1fe96edca93547b467a07295e0b6a1b8143af476
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Maus / Checkpoint.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class Checkpoint : MonoBehaviour
6 {
7     public GameObject[] CheckPoints;
8
9     public GameObject Mouse;
10
11     private Abyss abyss;
12     private Health health;
13
14     [HideInInspector]
15     public bool reset;
16
17     // Start is called before the first frame update
18     void Start()
19     {
20         abyss = GetComponent<Abyss>();
21         health = GetComponent<Health>();
22     }
23
24     // Update is called once per frame
25     void Update()
26     {
27         if (abyss.fallenDown == true || health.mouseHealth == 0)
28         {
29             reset = true;
30         }
31
32         if (reset == true)
33         {
34             for (int i = 0; i < CheckPoints.Length; i++)
35             {
36                 if (CheckPoints[i].transform.position.x <= Mouse.transform.position.x && CheckPoints[i + 1].transform.position.x >= Mouse.transform.position.x && CheckPoints[CheckPoints.Length-1].transform.position.x > Mouse.transform.position.x)
37                 {
38                     Mouse.transform.position = CheckPoints[i].transform.position;
39                 }
40                 else if (CheckPoints[0].transform.position.x >= Mouse.transform.position.x)
41                 {
42                     Mouse.transform.position = CheckPoints[0].transform.position;
43                 }
44                 else if (CheckPoints[CheckPoints.Length - 1].transform.position.x <= Mouse.transform.position.x)
45                 {
46                     Mouse.transform.position = CheckPoints[CheckPoints.Length - 1].transform.position;
47                 }
48
49                 if (Mouse.transform.position == CheckPoints[i].transform.position || Mouse.transform.position == CheckPoints[CheckPoints.Length - 1].transform.position)
50                 {
51                     reset = false;
52                     abyss.fallenDown = false;
53                     if(health.mouseHealth == 0)
54                     {
55                         health.mouseHealth = 5;
56                     }
57                 }
58             }
59         }
60     }
61 }