Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 MKayJay · Oct 07, 2013 at 12:17 PM · audio source

How do I play an ambient sound from an ocean surrounding an island?

I am making an island and I want the ocean around it to play an ambient "ocean sound", but I am not sure how I would do that?

I know the basics of audio sources and such, but if I want the same ambient sound to play when near the beach (with a falloff), how would I make the source to be the entire ocean around the island? Putting the source on the "water" object, wouldn't do any good, since the water is "under" the island as well.

I am pretty new to the 3D part of game design, so it might just be me being a bit confused :)

In short: How do I make an ambient sound effect play whenever I am near the edge of the island? Preferably with a falloff so the sounds gets softer the further away from the beach you get.

Thanks in advance :-)

Comment
Add comment · Show 1
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 anunitydy · Mar 07, 2016 at 08:31 PM 0
Share

I am new to Unity, so this may be a bad idea, but what about attaching this sound to the player ins$$anonymous$$d of the ocean, and just play it based on proximity to the water? Seems like that might be easier than having to have AudioSources spread around?

3 Replies

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

Answer by DaveA · Oct 07, 2013 at 12:27 PM

This is a perfect application for Audio Brush, coming soon to the Asset Store. See http://qlcomp.com/?page_id=61 for updates. Should be very soon! (I used this for the exact purpose to class-up an Oculus Rift demo).

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
2

Answer by jakejolli · Mar 07, 2016 at 07:08 PM

**NOTE: If you're going to use this, you'll have to change "FPSController" in the script to whatever you've named your player gameobject.

I encountered this issue too. Didn't find a whole lot of great answers, but here's the solution I went with:

Create an empty GameObject with an AudioSource component, and assign its AudioClip to be the sound you want played. Place this GameObject near the shore (preferably in the water, where the player can't go). Duplicate the GameObject, placing more of them around the shoreline. They don't have to be super close, but I usually position them so that their MaxDistance gizmos overlap a bit. Then give them all a common tag, I used "WaterSound".

Then, attach this script to some GameObject in your scene (could be your player, or just an empty object):

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class WaterSoundHandler : MonoBehaviour {
 
     public List<AudioSource> waterSounds;
     private GameObject player;
     public float volumeReductionSpeed = .5f;
 
     void Start () {
         //Find all of the Water AudioSources 
         foreach (GameObject obj in GameObject.FindGameObjectsWithTag("WaterSound")) {
             waterSounds.Add(obj.GetComponent<AudioSource>());
         }
 
         player = GameObject.Find("FPSController");      
     }
     
     void Update () {
         DetermineClosestWaterSound();       
     }
 
     void DetermineClosestWaterSound() {
         float distance = float.MaxValue;
         AudioSource closestWaterSound = null;

         //Determine which water sound is the closest
         foreach(AudioSource waterSound in waterSounds) {
            float newDistance = Vector3.Distance(player.transform.position, waterSound.transform.position);
             if (newDistance < distance) {
                 distance = newDistance;
                 closestWaterSound = waterSound;
             }
         }
 
         DisableDistantWaterSounds(closestWaterSound);
     }
 
         //Scale up the closest water sound's volume until it's reached 1.
         //Scale down the volume of any water sound that isn't closest.
     void DisableDistantWaterSounds(AudioSource closestWaterSource) {
         foreach(AudioSource waterSound in waterSounds) {
             if(waterSound != closestWaterSource) {
                 waterSound.volume -= volumeReductionSpeed * Time.deltaTime;
             } else {
                 waterSound.volume += volumeReductionSpeed * Time.deltaTime;
             }
         }
     }
 }

I originally tried just enabling/disabling the audiosources, but the 3D sound became a bit jumpy. Slowly changing the volume helps to blend the two audiosources together better when transitioning.

This can also sometimes be a bit jumpy, but the more audiosources (within reason) that you have, the smoother/more natural the transition.

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 Elievar · Jan 26, 2021 at 12:15 PM 0
Share

Works very well !

avatar image
0

Answer by Llama_w_2Ls · Jan 26, 2021 at 01:02 PM

Well surely, the best way to do this would be to have an audio source directly next to the player, or on the camera, that contains the sound of the ocean. Then increase the volume, when you get closer to the ocean. Creating lots of audio sources and scattering them around seems a bit over the top.

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

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

Destroying object without interrupting audio source? 2 Answers

How to play music/audio 2 Answers

How do I play audio once in Update? 1 Answer

Muiltiple Audio Sources Pitch 2 Answers

Some audios don't play in the build as long as their distance level is intersecting with others of the same kind 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