Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ObiWanToKnowMe · Nov 12, 2015 at 04:10 PM · c#unity 5audiosourceaudioclipsound effects

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.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ZefanS · Nov 13, 2015 at 02:36 AM 0
Share

Can you post a screenshot with the inspector settings for the AudioSource you're using for the sound effects?

avatar image ObiWanToKnowMe ZefanS · Nov 13, 2015 at 07:41 PM 0
Share

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

avatar image ObiWanToKnowMe ZefanS · Nov 13, 2015 at 09:57 PM 0
Share

alt text

Here's the screenshot

screencap.png (21.5 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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");
  }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ObiWanToKnowMe · Nov 13, 2015 at 07:42 PM 0
Share

Haven't tried that yet, I'll update you within an hour. Thank you for the suggestion

avatar image ObiWanToKnowMe · Nov 13, 2015 at 09:54 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges