Hello Unity,
I’m learning to code in JS (I know its not the best but its a good start) I’m having an issue adding audio to my game-object or will i have to make an audio script on its own & add it to an empty & place that by the object that’s getting destroyed? As of right now the object gets destroyed right away then particle get remove 4 seconds after when player hits said object. Script i’m using is below; (This is health for the objects)
// This section is health for the object when hits 0 its destroys itself.
var health :int = 8;
function Damage(damage:int){
health -= damage;
if(health <= 0)Destroy(gameObject);
}
// This section is for effect to play when object is destroyed.
var explosion: GameObject;
function OnCollisionEnter(){
var expl = Instantiate(explosion, transform.position, Quaternion.identity);
Destroy(gameObject);
Destroy(expl, 4); // Deletes the effect after 4 seconds of when object is destroyed.
}
// This section is Sound (Not working)
var reload : AudioClip;
Thank you if anyone can help me today
Luke