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
0
Question by kekrot · Mar 20, 2014 at 01:49 PM · arrayaudioclip

How do I assign audio files to an AudioClip[] array?

I'm trying to assign audio files (wav) to an array so that the script can play the music for the level I'm in and so on, and to make other objects/scripts check which music is playing. Here is my code so far (C#):

     //Declaring the variable
     public AudioClip[] list;
 
     void Start ()
         {
             //Loading the items into the array
             list =  new AudioClip[]{(AudioClip)Resources.Load("Sound/Music/intro.wav"),
                                     (AudioClip)Resources.Load("Sound/Music/level1.wav"), 
                                     (AudioClip)Resources.Load("Sound/Music/level2.wav"), 
                                     (AudioClip)Resources.Load("Sound/Music/level3.wav")};
         }

But when I play my scene the only thing happening is that I see the array in the inspector grow up to make place for four items, which is right, but the slots are empty (music wasn't put in them) What's wrong with the code?

Thanks in advance for your help.

Comment
Add comment · Show 2
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 stevethorne · Mar 20, 2014 at 01:59 PM 0
Share

Resources.Load loads from the Assets/Resources/ folder in your project, is the Sound folder inside of your Resources folder? It might not be finding those audio files.

avatar image kekrot · Mar 20, 2014 at 02:50 PM 0
Share

Ahh, thank you. For some reason I thought Resources.Load loads from the Assets as the root folder.

1 Reply

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

Answer by Dblfstr · Mar 20, 2014 at 02:08 PM

@stevethorne is correct. Your audio files should be inside of a folder named Resources, in order for Resources.Load to work.

Also, to load resources this way, you must leave off the extension of the file i.e. "level1.wav" would be "level1". More so, if your path is Assets/Resources/Sound Then you would do

 Resources.Load("Sound/Level1");

Here is some info on resources.Load https://docs.unity3d.com/Documentation/ScriptReference/Resources.Load.html

And here for nested folders: http://answers.unity3d.com/questions/199313/resourcesload-folders-path.html

Comment
Add comment · Show 3 · 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 Dblfstr · Mar 20, 2014 at 02:10 PM 0
Share

And remember, everything in the Resources folder will be included in the build, even if it is not used.

avatar image kekrot · Mar 20, 2014 at 02:52 PM 0
Share

Thanks all of you, it now works perfectly after combining your answers.

avatar image Arju2011 · Apr 12, 2015 at 11:51 PM 0
Share

Is there an updated version of this? I just tried this and it says its an outdated script.

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

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

Related Questions

Instanced Prefabs: Audio clip array out of range 1 Answer

Make the audio manager select from an array of sounds 1 Answer

Need help to play a random explosion sound from an array. 1 Answer

Best Way to Sequence AudioClips in an Array 1 Answer

Issues with random music player 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