]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Enemies/Boss/BossCollision.cs
Inivincibilty Frames for the snail
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Enemies / Boss / BossCollision.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class BossCollision : MonoBehaviour
6 {
7     Boss boss;
8
9     SpriteRenderer spriteRenderer;
10
11     public float flashingTime;
12     bool invulnerable;
13
14     private void Start()
15     {
16         boss = GetComponent<Boss>();
17         spriteRenderer = GetComponent<SpriteRenderer>();
18     }
19
20     //Bei Beruehrung mit der Schere wird die Gesundheit um 1 verringert
21     public void OnCollisionEnter2D(Collision2D collision)
22     {
23         if (boss.bossfight && !invulnerable)
24         {
25             if (collision.gameObject.CompareTag("Bullet"))
26             {
27                 boss.bossHealth--;
28                 Destroy(collision.gameObject);
29                 StartCoroutine("GetInvincible");
30             }
31         }
32     }
33
34     IEnumerator GetInvincible()
35     {
36         invulnerable = true;
37         Physics2D.IgnoreLayerCollision(7, 8, true);
38         for (int i = 0; i < 4; i++)
39         {
40             spriteRenderer.enabled = false;
41             yield return new WaitForSeconds(flashingTime);
42             spriteRenderer.enabled = true;
43             yield return new WaitForSeconds(flashingTime);
44         }
45         Physics2D.IgnoreLayerCollision(7, 8, false);
46         spriteRenderer.enabled = true;
47         invulnerable = false;
48     }
49 }