using UnityEngine;
public class Target : MonoBehaviour {
public float health = 10f;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
using UnityEngine;
public class Target : MonoBehaviour {
public float health = 10f;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
Import that mp3 into unity. Change the code to this:
public float health = 10f;
public AudioClip deathClip;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die()
{
AudioSource.PlayClipAtPoint (deathClip, transform.position);
Destroy(gameObject);
}
Then, drop the mp3 into the death clip slot in inspector window