-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerHealth.cs
60 lines (49 loc) · 1.16 KB
/
PlayerHealth.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
55
56
57
58
59
60
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHealth : MonoBehaviour
{
public int maxhealth = 100;
public int currentHealth;
public Animator playerAnim;
public PlayerHealthBar healthBar;
private AudioSource audioSource;
public AudioClip heartBeatMedium;
public AudioClip heartBeatNormal;
private void Start()
{
currentHealth = maxhealth;
healthBar.SetMaxHealth(maxhealth);
audioSource = GetComponent<AudioSource>();
}
public void TakeDamage(int damage)
{
if (!GetComponent<PlayerMove>().isDashing && currentHealth >= 0)
{
currentHealth -= damage;
healthBar.SetHealth(currentHealth);
playerAnim.SetTrigger("Hit");
}
if (currentHealth <= 0)
{
Die();
}
if(currentHealth <= 60)
{
audioSource.clip = heartBeatNormal;
audioSource.loop = true;
audioSource.Play();
}
if(currentHealth <= 40)
{
audioSource.clip = heartBeatMedium;
audioSource.loop = true;
audioSource.Play();
}
}
void Die()
{
playerAnim.SetBool("isDead", true);
GameManager.instance.GameOver();
}
}