blob: c9d93be8eb98f91d8b1df8eff2ce5b7328685a2f (
plain)
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
|
using UnityEngine;
using System.Collections;
public class EnemyHealthScript : MonoBehaviour {
public int Health = 100;
public GameObject DestroyAnimation;
GameObject DestroyAudio;
void Start () {
DestroyAudio = GameObject.FindGameObjectWithTag("EnemyDestroyAudio");
}
// Update is called once per frame
void Update () {
}
public void TakeDamage(int damage)
{
Health -= damage;
if (Health <= 0)
{
var animation = Instantiate(DestroyAnimation, transform.position, Quaternion.identity);
DestroyAudio.GetComponent<AudioSource>().Play();
Destroy(gameObject);
Destroy(animation, 1f);
}
}
}
|