- Home /
This question was
closed Jan 23, 2015 at 08:42 AM by
meat5000 for the following reason:
Duplicate Question
Question by
KenjiHyorinmaru · Jan 23, 2015 at 07:30 AM ·
explosionsfx
Based on my (C Sharp ) code, how would I add my explosion sound when i destroy the enemy?
// The speed to use when in "ramming" mode
[SerializeField] float RamSpeed = 5.0f;
// The different IDs fo the AI states
enum AIMode {Normal, Ramming, SteerTowards, Charge, Avoid };
// The variable which holds the current AI state
private AIMode CurrentAIState;
// List of pickup TYPES to spawn
[SerializeField]GameObject[] PickupTypes;
// Holds the audio clip to play
// when this object is spawned
[SerializeField]AudioClip EnemyDestSfxClip;
// The particle system to spawn when the
// projectile collides with something.
[SerializeField]GameObject EnemyParticles;
// The game object which spawned us.
private ShipPlayerController PlayerShipCtrl;
// Used to control how fast the game object moves
[SerializeField] float MoveSpeed = 3.0f;
// Instantiates a particle when something is hit.
// Represents the "death of THIS game object, not
// the desruction of what the projectile hit.
void SpawnEnemyParticles()
{
Instantiate (EnemyParticles,
transform.position, transform.rotation);
}
// A customized version of the destroy function
void StartDestroy(float timeDelay)
{
// Turn off drawing and colliding
renderer.enabled = false;
collider.enabled = false;
// Start the destroy countdown
Destroy (gameObject, timeDelay);
}
Comment
how to make it, when i shoot the enemy ship and it explodes, i wanna hear the explosion sound as it explodes, really confuse on that part
Answer by sniper43 · Jan 23, 2015 at 08:38 AM
http://docs.unity3d.com/ScriptReference/AudioSource.PlayClipAtPoint.html
Use this. Creates a new GameObject (which has no body, is only an audiosource) and you can freely destroy your enemies while retaining the 3D position of the sound (the Audio self-destructs on completion).
Answer by JustinC · Jan 23, 2015 at 07:39 AM
Add a Public AudioClip explode; then in your void StartDestroy function add explode.Play()
This doesn''t work, as it destroys the auido source as well. I posted an answer below.