]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Enemies/Boss/Boss.cs
Dialog-System 0.4
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Enemies / Boss / Boss.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5
6 public class Boss : MonoBehaviour
7 {
8     [SerializeField]
9     string bossName;
10
11     [SerializeField]
12     Text bossText;
13
14     [SerializeField]
15     GameObject bossTriggerObj;
16
17     public int bossHealth;
18     public int numberOfHearts;
19     public bool bossfight = false;
20
21     public Image[] bossHearts;
22     public Sprite fullHeart;
23     public Sprite emptyHeart;
24
25     // Update is called once per frame
26     void Update()
27     {
28         if(bossfight)
29         {
30             bossText.enabled = true;
31             bossText.text = bossName;
32             GetComponent<FollowPlayer>().enabled = true;
33         }
34         else
35         {
36             bossText.enabled = false;
37             GetComponent<FollowPlayer>().enabled = false;
38         }
39
40         if (bossHealth > numberOfHearts)
41         {
42             bossHealth = numberOfHearts;
43         }
44
45         for (int i = 0; i < bossHearts.Length; i++)
46         {
47             //Wenn i kleiner als die Gesundheit, zeige ein volles Herz an, ansonsten ein leeres
48             if (i < bossHealth)
49             {
50                 bossHearts[i].sprite = fullHeart;
51             }
52             else
53             {
54                 bossHearts[i].sprite = emptyHeart;
55             }
56
57             if (i < numberOfHearts)
58             {
59                 bossHearts[i].enabled = true;
60             }
61             else
62             {
63                 bossHearts[i].enabled = false;
64             }
65
66             if(!bossfight)
67             {
68                 bossHearts[i].enabled = false;
69             }
70         }
71
72         if (bossHealth <= 0)
73         {
74             gameObject.SetActive(false);
75             bossText.enabled = false;
76             for (int i = 0; i < bossHearts.Length; i++)
77             {
78                 bossHearts[i].enabled = false;
79             }
80         }
81     }
82
83     //Bei Beruehrung mit der Schere wird die Gesundheit um 1 verringert
84     public void OnCollisionEnter2D(Collision2D collision)
85     {
86         if (bossfight)
87         {
88             if (collision.gameObject.CompareTag("Bullet"))
89             {
90                 bossHealth--;
91                 Destroy(collision.gameObject);
92             }
93         }
94     }
95 }