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 Addyarb · Sep 22, 2014 at 10:41 PM · menusettings

Gather AudioSources in an Array?

Hi Unity,

I'm making a game right now with 3 scenes:

 Splash/MainMenu
 Options
 Game

So, I would like the options scene to give the player a chance to edit simple settings such as volume, render settings, etc.

I have created a GameObject called "Options" and placed it in the Splash/MainMenu scene, and set DontDestroyOnLoad in the start function, so this should persist through my scenes if I assume correctly.

I would like to create some audio sliders and set the volume of every single AudioSource in the current scene to that float, but I'm confused on how to capture these in an array/list. Which would be easier/more efficient, and how should I capture them?

Thanks! Addyarb

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 Eric5h5 · Sep 22, 2014 at 10:46 PM 0
Share

Why not just set the volume of the audio listener?

avatar image Addyarb · Sep 22, 2014 at 10:49 PM 0
Share

Good point! Would this work as well in the multiplayer version of my game?

avatar image Addyarb · Sep 22, 2014 at 10:50 PM 0
Share

Also, how would one go about editing the receiving volume of an Audio Listener?

avatar image Eric5h5 · Sep 22, 2014 at 11:54 PM 0
Share

http://docs.unity3d.com/ScriptReference/AudioListener-volume.html

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by TwixEmma · Sep 23, 2014 at 01:55 AM

You can do this to get all the audio sources in your scene:

C#

 AudioSource[] audioSources = Object.FindObjectsOfType(typeof(AudioSource)) as AudioSource[];

JS

 var audioSources = Object.FindObjectsOfType(AudioSource);

EDIT: Answer updated to reflect comments, thanks for the feedback I don't natively code JS myself.

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 Eric5h5 · Sep 23, 2014 at 02:05 AM 0
Share

FindObjectsOfType returns the type in JS, actually (despite what the docs imply), so casting is unnecessary. Nor do you need to use Object since Object is the base class for everything anyway. This is fine:

 var audioSources = FindObjectsOfType(AudioSource);
avatar image Addyarb · Sep 23, 2014 at 04:22 AM 0
Share

Are you saying in C# you need to create an array but in JS you don't?

avatar image Eric5h5 · Sep 23, 2014 at 04:44 AM 0
Share

What? No. I don't understand that question. :) FindObjectsOfType returns an array; which language you use has nothing to do with it.

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

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

Related Questions

Save information on Level Load HELP 1 Answer

How do i add an extra menu to my main menu (I'm a Beginner programmer!) 1 Answer

adjust video settings in game 1 Answer

Trouble with writing text to a .ini file 1 Answer

How to make main menu including settings? 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