]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Maus/Health.cs
9d04ef6c85f67fb330016e071e16ec7caa9aad71
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Maus / Health.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5
6 public class Health : MonoBehaviour
7 {
8     public int mouseHealth;
9     public int numberOfHearts;
10
11     public Image[] hearts;
12     public Sprite fullHeart;
13     public Sprite emptyHeart;
14
15     PowerUps powerUps;
16
17     InvincibilityFrames invincibility;
18
19     private void Start()
20     {
21         powerUps = GetComponent<PowerUps>();
22         invincibility = GetComponent<InvincibilityFrames>();
23     }
24
25     // Update is called once per frame
26     void Update()
27     {
28         if(mouseHealth > numberOfHearts)
29         {
30             mouseHealth = numberOfHearts;
31         }
32
33         for (int i = 0; i < hearts.Length; i++)
34         {
35             //Wenn i kleiner als die Gesundheit, zeige ein volles Herz an, ansonsten ein leeres
36             if(i < mouseHealth)
37             {
38                 hearts[i].sprite = fullHeart;
39             } else
40             {
41                 hearts[i].sprite = emptyHeart;
42             }
43
44             if(i < numberOfHearts)
45             {
46                 hearts[i].enabled = true;
47             } else
48             {
49                 hearts[i].enabled = false;
50             }
51         }
52     }
53
54     //Bei Ber?hrung mit einem Gegner wird die Gesundheit um 1 verringert
55     private void OnCollisionEnter2D(Collision2D collision)
56     {
57         if(collision.gameObject.CompareTag("Enemy") || collision.gameObject.CompareTag("Boss") && invincibility == false)
58         {
59             mouseHealth--;
60             powerUps.mouseIsGardener = false;
61             invincibility.invincible = true;
62         }
63
64         if(invincibility.invincible == true)
65         {
66             if (collision.gameObject.CompareTag("Enemy") || collision.gameObject.CompareTag("Boss"))
67             {
68                 Physics2D.IgnoreCollision(collision.collider, collision.collider);
69             }
70         }
71     }
72 }