-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthPoint
More file actions
61 lines (48 loc) · 1.61 KB
/
Copy pathHealthPoint
File metadata and controls
61 lines (48 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealthPoint : MonoBehaviour
{
public int value;
public int playerCurHealth;
public int playerMaxHealth;
private BossSpawnHealthPoints spawner;
public int bossNum = 0;
// Start is called before the first frame update
void Start()
{
playerMaxHealth = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>().maxHealth;
spawner = GameObject.FindGameObjectWithTag("Spawn Manager").GetComponent<BossSpawnHealthPoints>();
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
playerCurHealth = other.gameObject.GetComponent<PlayerController>().curHealth;
//add health if it isnt at max already
if (playerCurHealth == playerMaxHealth)
{
//Player is already at max health
}
else
{
other.gameObject.GetComponent<PlayerController>().SetHealth(playerCurHealth + value);
other.gameObject.GetComponent<PlayerController>().healthBar.SetHealth(playerCurHealth + value);
}
//check if it was spawned by boss
if (bossNum == 1 || bossNum == 2 || bossNum == 3)
{
spawner.SetDestroyed(bossNum);
Destroy(gameObject);
}
else
{
Destroy(gameObject);
}
}
}
}