blob: b2d830801e00564984a7ee910f7c0da7de6b616f (
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
32
33
34
|
using UnityEngine;
using System.Collections;
public class Enemy3HealthScript : MonoBehaviour {
public int Health = 100;
public GameObject DestroyAnimation;
GameObject DestroyAudio;
void Start()
{
DestroyAudio = GameObject.FindGameObjectWithTag("EnemyDestroyAudio");
}
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(animation, 1f);
Destroy(transform.parent.gameObject);
}
}
}
|