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 /
avatar image
1
Question by Sisso · Aug 23, 2013 at 02:50 PM · audioplayoneshot

It is possible to have a random audio pitch with one AudioSource and PlayOneShot?

This sample only work when play one audio, when I call it again, both clips play with new pitch.

 function Play(audioClip: AudioClip) {
   audio.pitch = Random.Range(0.5, 1.5);
   audio.PlayOneShot(clip, Random.Range(0.8, 1.2));
 }

My solution is to use a pool of audiosource and controlling by self what source is being used, because PlayOneShot don't update AudioSource.isPlaying).

I think a little wierd, but it is the way?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Sisso · Aug 28, 2013 at 12:57 PM

Because I have no answer I will consider as "No, your best solution is to create a pool of sources."

Comment
Add comment · Show 1 · 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 komodor · Apr 13, 2017 at 11:05 AM 0
Share

yes, it's the only solution right now

avatar image
12

Answer by M_R_M · Mar 29, 2019 at 05:02 AM

Anyone who is looking for a solution to this just like I was, ignore the snark and venom that Calum and komodor couldn't seem to help themselves with, AlpayKasal's answer worked perfectly for me with playoneshot, and can be very easily applied to JS as well.

These older threads often come up first in google searches, so I'm grateful people respond with solutions, even if they are on old threads. If the question persists and comes up first when looking for a solution, by all means, LET'S RESOLVE IT.

This pool of resources is what makes Unity unique, so Calum and komodor's responses are as inappropriate as they are wrong and detrimental to the very idea of Unity and the reason we're all using it.

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 Calum_1015 · Mar 29, 2019 at 05:28 PM 1
Share

Community guidelines state that this should be a comment, by the way. The reasoning behind not resurrecting old threads is simply that the users are generally not active, and the premise of the question can be out of date to the version of the game engine used at the time of the question.

avatar image JustStopAndThink Calum_1015 · Nov 07, 2019 at 05:47 PM 3
Share

And yet it's still toward the top in the Google search result for "unity play sound at random pitches" (#2 for me).

I think this is what he was saying: Even if the information herein is obsolete/deprecated/whatever, it still comes up and is therefore relevant, if only to pass folks along to the real/needed/better answers.

avatar image
10

Answer by AlpayKasal · Jul 04, 2016 at 01:32 PM

@sisso this is an old thread but I thought I'd answer anyway, for future googlers:

put an f character after your floats in the random ranges, that's the first problem I see... here's some code that s working for me (I needed pitch variations).

 public class plinkotrigger : MonoBehaviour {
     private AudioSource audioSource;
     public AudioClip Snare;
 
     void OnCollisionEnter(Collision col)
     {
         if (col.gameObject.name == "bullets(Clone)")
         {
             audioSource = GetComponent<AudioSource>();
             audioSource.clip = Snare;
             audioSource.pitch = (Random.Range(0.6f, .9f));
             audioSource.Play();
         }
     }
 }
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 Calum_1015 · Jul 29, 2016 at 02:44 AM 1
Share

@Alpay$$anonymous$$asal This is a very old thread that didn't need resurrecting. Also, he was using javascript, and such does not need to add the f character behind his float variables. Please, pay a bit of attention before responding to such an old thread!

avatar image komodor · Apr 13, 2017 at 11:05 AM 4
Share

it's nonsense, he's asking for PlayOneShot and you respond with Play, it's different method dude and it does different thing :D

not mentioning the F after float ROFL :D

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio trigger by key press - problems 1 Answer

My soundclip is noisy? 2 Answers

AudioSource.PlayOneShot only works ONCE on Unity 5? 1 Answer

AUDIO ISSUES - PlayOneShot... is cutting short... I think? 2 Answers

PlayOneShot keeps playing for ever (loops) 2 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