forked from GrzegorzBaweda/DisGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyHealthManager.cs
54 lines (39 loc) · 1.15 KB
/
EnemyHealthManager.cs
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
using UnityEngine;
using System.Collections;
public class EnemyHealthManager : MonoBehaviour {
public int enemyHealth;
public GameObject deathEffect;
public int pointsOnDeath;
private bool died;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (enemyHealth <= 0 && died == false)
{
Instantiate(deathEffect, transform.position, transform.rotation);
ScoreManager.AddPoints(pointsOnDeath);
GetComponent<AudioSource> ().pitch = 1f;
if (this.GetComponent<EnemyHealthBar> ()) {
this.GetComponent<EnemyHealthBar> ().giveDmg (0);
}
died = true;
Destroy(gameObject);
}
}
public void giveDamage (int damageToGive)
{
enemyHealth -= damageToGive;
GetComponent<AudioSource> ().pitch += 0.1f;
GetComponent<AudioSource> ().Play ();
if (this.GetComponent<EnemyHealthBar> () == true)
{
if(this.GetComponent<EnemyHealthBar> ().hitted != true) //jesli pierwszy raz
{
this.GetComponent<EnemyHealthBar> ().hitted = true;
}
this.GetComponent<EnemyHealthBar> ().giveDmg (enemyHealth);
}
}
}