- Home /
Having problems with playing a sound (C#)
I'm trying to make that in my game, the guns shoot darts, and you'll be able to pick them up and use them again.
What is supposed to happen, is that the item has a big box collider around, which is a trigger, if the player is within that area, the item gets destroyed, the gun's ammo goes up by 1, and it has to play a sound, which informs the player they've picked up a shot dart.
The picking up part works, it doesn't play any sound because the game can't play a "Disables Audio Source", the problem is... it ISN'T disabled...
Here's the code:
//public GameObject pickUpParticleEffect;
public AudioClip audioSource;
// public GameManager masterScript;
public RayShoot weaponScript;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
audio.PlayOneShot(audioSource);
weaponScript.bulletsLeft++;
Destroy(gameObject);
}
}
How do I fix this?
Answer by Jessy · Jan 17, 2013 at 08:31 PM
You destroy the Game Object. Therefore, there is no Audio Source.
Answer by ragnaros100 · Jan 17, 2013 at 08:39 PM
Simply set a timer on, after you've played the sound. Then destroy the object