My audio doesn't play, I'm through my options...
I'm building a simple breakout game and I want to play a sound everytime you hit a block. I've tried everything but it keeps saying that it can't play disabled sounds. Here is a piece of my code from the bricks (note: I'm just a beginner so I may have overlooked things)
 using UnityEngine;
 using System.Collections;
 public class Bricks : MonoBehaviour {
     
     public GameObject brickParticle;
 
     void Awake ()
     {
     }
 
     void OnCollisionEnter (Collision other)
     {
         Instantiate(brickParticle, transform.position, Quaternion.identity);
         GM.instance.DestroyBrick();
         Destroy(gameObject);
     }
 
 }
 
               And here is the code for the sound I want to play
 using UnityEngine;
 using System.Collections;
 [RequireComponent(typeof(AudioSource))]
 public class BrickDestroy : MonoBehaviour {
 
     public AudioClip brickBreak;
     private AudioSource source;
 
     // Use this for initialization
     void Awake () 
     {
         source = GetComponent<AudioSource>();
     }
     
     void OnCollisionEnter(Collision coll)
     {
 
         source.PlayOneShot(brickBreak, 1F);
         Debug.Log ("Sound Played");
     }
 }
 
 
               I've searched most forums without success, I really hope someone can help me here. If you need more information, feel free to ask. Thanks in advance.
EDIT: Does anyone know how to set a delay between the destruction of the bricks and the audio? I figured out when I play the game in the editor and change a timescale in the GM script, the bricks won't break down but sound does play.
Can you post a screenshot with the inspector settings for the AudioSource you're using for the sound effects?
Sorry for the late reply. Can't post a screenshot right now, but im 100% sure the audiosource is enabled and every option that could cause it is unchecked. Will post a screenshot when im home
Answer by Jessespike · Nov 13, 2015 at 07:36 PM
Can not play a disabled audio source
This warning is thrown when the AudioSource is disabled and the code tries to play a sound (PlayOneShot). A silly question: Is the audio source enabled?
What if you try something like this:
  void OnCollisionEnter(Collision coll)
  {
      source.enabled = true;
      source.PlayOneShot(brickBreak, 1F);
      Debug.Log ("Sound Played");
  }
 
              Haven't tried that yet, I'll update you within an hour. Thank you for the suggestion
The disabled audio message is gone, but I still don't hear any sounds. Could it be because the brick gets destroyed so that there isn't an object to collide with? (saw this on a forum where they discussed this)
Your answer
 
             Follow this Question
Related Questions
How to add collection sound to watering can? 0 Answers
Play audio after enemy dies 1 Answer
AudioClip not playing 0 Answers
Precisely timestamping when audio leaves speaker 0 Answers
Audio Source stop playing even with "DontDestroyOnLoad" 0 Answers
