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 /
avatar image
2
Question by jimmyismike · Aug 29, 2011 at 11:20 PM · audiorandomclip

Random Audio Clip Help

Can you help me make a script where 7-8 audioclips play at random. Repeating is fine.

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
9
Best Answer

Answer by aldonaletto · Aug 29, 2011 at 11:51 PM

You can create an AudioClip array, then use Random.Range(0,audioClipArray.length) to select the sound randomly (Random.Range(0,max) draws an integer from 0 to max-1):

 var sounds: AudioClip[]; // set the array size and fill the elements with the sounds
 
 function PlayRandom(){ // call this function to play a random sound
     if (audio.isPlaying) return; // don't play a new sound while the last hasn't finished
     audio.clip = sounds[Random.Range(0,sounds.length)];
     audio.Play();
 }

NOTE: Add an AudioSource to the object owner of this script.

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 ArtOfWarfare · Oct 05, 2013 at 10:30 PM 0
Share

Very helpful, thank you. I'd +1 this but I have inadequate rep for that.

avatar image
2

Answer by vestax_ion · Aug 29, 2011 at 11:48 PM

ok, but maybe you have to use your brain abit and it will take an hour! in the process you will learn ALOT!

look at the play sound script in the UNITY REFERENCE... figure out how it works and make 7 8 variables for playing your sound... http://answers.unity3d.com/questions/12546/playing-audio-clip.html

Secondly look at the RandomRange variable...you use this to select randomly things. by making a random number from one to 8 http://unity3d.com/support/documentation/ScriptReference/Random.Range.html

Then... look at ARRAYS!!!! fill an array with the varables for 7 sounds....

and then make a button like.... if jump button then play random sound from 1 to 8. and when you have it loading, then change jump to whatever trigger you want.

 var blocks : GameObject[]; ///declare an array except use soundobjects
 var ino = Instantiate(blocks[Random.Range(0, blocks.Length)], displace2 + displace, rot);///

use a line like this except instead of instantiate, say ... PLAY sound 1 to 8... blocks length is 8 if you have 8 sounds. using the oplay commands,

that is all, 3 lines, figure out how to use code!!!

you can alternatively declare and fill an array with this kind of logic:

 var array2 = new Array (Vector3(0, 0, 0),Vector3(0,0,-90),Vector3(0, 0, 180),Vector3(0, 0, -270) , Vector3(90, 0, 0) ,Vector3(-90, 0, 0),Vector3(0, 0, 0),Vector3(0,0,90),Vector3(0, 0, -180),Vector3(0, 0, -270) , Vector3(90, 0, 0) ,Vector3(-90, 0, 0));

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

Answer by dar0307 · Jul 29, 2014 at 11:13 PM

i'm sorry, i'm trying get a little help, but if you can't help me... fine no problem :D

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

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

8 People are following this question.

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

Related Questions

How to get the AI enemy character to play random audio clips over time? 1 Answer

Random, 3d sound. 1 Answer

Audio clip not triggering 1 Answer

Buzzing noise instead of my audio-clip? 0 Answers

audio troubles changing from one to another (stop it consistently changing) 1 Answer


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