- Home /
My sound will play immediately when i start my game.
i've been making a simple script (JS), to make a crate (gameObject) disappear when it doesn't have any HP left; and a simple sound of a crate being damaged. but for some reason my sound plays when i start the game, and it can't be heard after that. A little help would be appreciated :). Here's my script:
var EnemyHealth : int = 10;
var cratedamage : AudioSource = GetComponent.();
function DeductPoints (DamageAmount : int)
{
EnemyHealth -= DamageAmount;
}
function Update ()
{
if (EnemyHealth <= 0) {
Destroy(gameObject);
cratedamage.Play ();
}
}
Select your gameobject on which you have attached the sound/music. And, under AudioSource
component, Un-check "Play on Awake".
Your answer
Follow this Question
Related Questions
all my walls teleported to one spot 0 Answers
Is Unity3D capable of handling a MMo 3 Answers
Using two animations at once 1 Answer
How to create a stationary weapon FPS controller ? 2 Answers
How do I check if an Animation is playing in an animator 0 Answers