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
0
Question by Catsby · Jun 06, 2011 at 11:56 PM · javascriptarraysoundstudent

Trouble loading sounds into array

Hey everyone. I'm trying to load a handful of sound files into an array via Javascript but the zeroth spot refuses to cooperate. I have all the sound file's names in a string array and load the audio clip array using a for loop. Initially I thought the problem was the for loop but tried manually loading individual slots and found that all besides the very first slot will load via the script. If I try dragging and dropping a file from the resources folder into the array during runtime it works fine but players obviously can't do that. Has anybody ever run into a problem like this before or does anybody have a possible solution?

Here's basically what the JS looks like;

 var sound  = new AudioClip[6];
 var sfile : String[] = ["Chime_01","Fireball_01","Roar_01","Snarl_01","Stomp_01","Sword_01"];

then later in Start()...

 for ( var j : int = 0; j < 6; j++){
     sound[j] = Resources.Load(sfile[j]);

Then in inspector I always see this...

Sound

size 6

Element 0 None(Audio Clip)

Element 1 Fireball_01

Element 2 Roar_01

Element 3 Snarl_01

Element 4 Stomp_01

Element 5 Sword_01

bizarre... Anyways thanks for your help in advance.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Jun 07, 2011 at 02:36 AM

I've tried the same thing, but it worked for me. I had problems initially because my sound files were in the wrong folder, so all elements of sound[] became empty - but I had no error messages. When I finnally put the files in the right folder, it worked for all elements of the array. Could the first file name of your list be misspelled, or in a folder other than Resources?

Comment
Add comment · Show 8 · 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 Joshua · Jun 07, 2011 at 02:42 AM 0
Share

Since entry one to five are placed in slot one to five, the only obvious reason for it 'skipping' entry zero is because the name is indeed misspelled or it's not in the correct folder. I'm assu$$anonymous$$g you have a closing } but you just didn't copy/paste it.

avatar image Catsby · Jun 07, 2011 at 02:44 AM 0
Share

You know, I thought so too and tried rena$$anonymous$$g the file and moving it around but that didn't seem to work. It does the same thing regardless of the file I'm trying to put in it. I'm going to try rena$$anonymous$$g the array and see if that fixes it or not.

avatar image Catsby · Jun 07, 2011 at 02:47 AM 0
Share

I also just straight up tried sound[0] = Resources.Load(filename here); and had the same problem. so weird...

avatar image Joshua · Jun 07, 2011 at 02:48 AM 0
Share

So you're saying that if, in the sfile:String[] array you switch "Chime_1" and "Fireball_1" it will still skip over entry zero in the sound:AudioClip[] array and not the first entry which would be expected if it couldn't find "Chime_1"?

avatar image Catsby · Jun 07, 2011 at 02:53 AM 0
Share

That is correct. I'm about to just delete the audioclip array and re declare it with a different name.

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Random Array of sounds for Random Game Object 1 Answer

Convert Array into One String (Js) 1 Answer

Help me Convert JS to C# 2 Answers

+= doesn't work with a 2d array in JS 1 Answer

Adding an object to an array of custom objects (JS) 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