]> git.lizzy.rs Git - SuperMouseAdventure.git/blobdiff - 2DGame/Assets/Scripts/Maus/Checkpoint.cs
Checkpoint-System v0.2
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Maus / Checkpoint.cs
index 1705cf26bad18d59a8ecd79e434587e5805e2450..7064863b4f9ea60ec36310d71f048ed7a5a22f3f 100644 (file)
@@ -4,49 +4,22 @@ using UnityEngine;
 
 public class Checkpoint : MonoBehaviour
 {
-    public GameObject[] CheckPoints;
+    private CheckpointManager cm;
 
-    public GameObject Mouse;
+    public Sprite red;
+    public Sprite green;
 
-    private Abyss abyss;
-    private Health health;
-
-    public bool reset;
-
-    // Start is called before the first frame update
     void Start()
     {
-        abyss = GetComponent<Abyss>();
-        health = GetComponent<Health>();
+        cm = GameObject.FindGameObjectWithTag("CheckpointManager").GetComponent<CheckpointManager>();
     }
 
-    // Update is called once per frame
-    void Update()
+    void OnTriggerEnter2D(Collider2D collision)
     {
-        if (abyss.fallenDown == true || health.mouseHealth == 0)
-        {
-            reset = true;
-        }
-
-        if (reset == true)
+        if(collision.CompareTag("Player"))
         {
-            for (int i = 0; i < CheckPoints.Length; i++)
-            {
-                if (CheckPoints[i].transform.position.x <= Mouse.transform.position.x && CheckPoints[i + 1].transform.position.x >= Mouse.transform.position.x)
-                {
-                    Mouse.transform.position = CheckPoints[i].transform.position;
-                } else
-                {
-                    Mouse.transform.position = CheckPoints[CheckPoints.Length - 1].transform.position;
-                }
-
-                if (Mouse.transform.position == CheckPoints[i].transform.position)
-                {
-                    reset = false;
-                    abyss.fallenDown = false;
-                    health.mouseHealth = 5;
-                }
-            }
+            cm.lastCheckpointPos = transform.position;
+            GetComponent<SpriteRenderer>().sprite = green;
         }
     }
 }