Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Sep 24, 2012 at 10:12 PM by SpectralEdge for the following reason:

Issue went away.

avatar image
0
Question by SpectralEdge · Sep 23, 2012 at 09:54 AM · audioclipplayoneshot

Oneshot only plays once?

Very simple code

     public AudioClip soundToPlay;
     public string tags;
         
     void OnCollisionEnter (Collision collision) {
     
         string[] splitTags = tags.Split(',');
         for(int i = 0; i <= splitTags.Length-1; i++)
         {
                audio.PlayOneShot(soundToPlay);        
         }


The first collision, it plays, the second and thereafter, it does not. If I change it to audio.play() and put the audio clip in the audio source, it works fine. But I want to apply multiple audio clips to a game object this way so why is this not working? Is there a better way?

Comment
Add comment · Show 4
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 Owen-Reynolds · Sep 23, 2012 at 03:23 PM 1
Share

Is this supposed to play different sounds?

The way it is now, if the sound is $$anonymous$$OO and tags is "arf,bong,score" then your code will play $$anonymous$$OO $$anonymous$$OO $$anonymous$$OO (three times at once, so one very loud moo.) Because the loop just says to say $$anonymous$$OO for each word in tags.

avatar image SpectralEdge · Sep 23, 2012 at 09:16 PM 0
Share

It plays one sound per tag. So for example, if i have a ball if it hits a wall, or floor it plays the bounce sound, I have another that plays a different sound if the ball hits another ball, etc.

So technically the engine only grabs the one tag of the object it impacts, so it will only play the sound the one time for the impact. But I need it to play it again the next time the ball bounces. Right now it is playing the first time the ball bounces, and nothing after that.

I see in the code I pasted I missed this line. if(collision.gameObject.tag == splitTags[i])

I assure you it is there in my normal code.

avatar image Owen-Reynolds · Sep 24, 2012 at 02:01 PM 1
Share

If a line can "fall out" of the middle of a paste, maybe some other lines have also fallen out and broken your game logic.

$$anonymous$$aybe add `Debug.Log("play sound");` next to each `audio.Play` to check if the sound or the code is the problem (w/Collapse unchecked in the error window.)

avatar image SpectralEdge · Sep 24, 2012 at 10:12 PM 0
Share

How odd. I think it may have been my sound system. Last night it was not working when I went to bed, today it works and I changed nothing.

1 Reply

  • Sort: 
avatar image
0

Answer by dotJack · Sep 23, 2012 at 10:57 AM

Are you sure the OnCollisionEnter calls it out properly each time?

If yes, you could try to instantiate a GameObject every time it is called, set it up with an AudioSource and a AudioClip, call it's play and then destroy the entire gameObject after length of AudioClip.

Building your own PlayOneShot that way.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fix my reload sound? 0 Answers

Need help with AudioSources 1 Answer

audioclip is not working 0 Answers

My AudioClip wont loop even though loop is true 1 Answer

2d PlayAudioOneShot inconsistent behavior 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