Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Audio not fading out and playing beyond maximum distance. ASAP!

Discussion in 'Editor & General Support' started by JamieLawson, Aug 12, 2014.

  1. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    Hi,

    I have my audio attached to a game object which is triggered via a box collider. That all works fine, however my problem is when i leave the area, i can still hear the audio playing beyond the maximum distance that i've set. Any way to resolve this? I need it sorted ASAP!!
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Need code.
     
  3. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    #pragmastrict

    functionOnTriggerEnter(other: Collider){
    if (!audio.isPlaying){
    audio.Play();
    }


    }
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  5. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    Yeah they are all 3D Sounds. i have a reverb zone as well to see if this would help with the fading out but its not.
     

    Attached Files:

  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You should get rid of the reverb zone, as it will impact the way in which you hear the audio and as such it makes it harder to resolve the issue.

    Did you check that you only have one AudioListener in the scene? Did you check that the AudioSource is not attached to the listener?
    How does it behave if you move away from the AudioSource? How does the heard volume change if you move away from the source? Does it fade out at all?
     
  7. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    Yeah i have only one listener in the scene. All the Audio Sources are attached to game objects.

    whenever i trigger the sound i walk away and it still plays as normal. no volume change or no fade out.
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Did check the scale of your scene?
     
  9. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    How do you do that?
     
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Create an empty game object, move it around, and check the position of it, such that you can be sure that what you think is one unit, is really one unit.
     
  11. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    Yeah, one unit is one unit it appears
     
  12. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Could you show the whole inspector of your audio source and the one of the audio listener?
     
  13. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    The code you provided only has to do with triggering, playing the audio. It has nothing to do with fading out audio.

    I cant help you with what you have shown.
     
  14. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    is there a way to make the audio fade out via script though?
     
  15. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    theres the photos you required
     

    Attached Files:

  16. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Read the text in the third image.
     
  17. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    audio.volume -= someFactor;

    repeat that method, over time. Via an update, coroutine etc.

    if audio.volume == 0, return.
     
  18. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    But the goal is to fade out by distance. That is already in Unity. There is no need for actual scripting. The problem is that JamieLawson has other scripts that influence the fading.
     
  19. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Oh.
    Can he not monitor Distance() and use this value to apply the fade factor?

    I would think so.



    Look up Distance(). Use this value to come up with a factor to reduce or increase your volume by.
     
  20. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Why waste resources if Unity supports it out of the box?
     
  21. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    It wont let me change the roll off curve if thats any help
     
  22. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    tbh, rn its not a case of wasting resources. Anything would help rn as the project is due within a few days so need this sorted asap aha
     
  23. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    If it helps. I am trying to change the volume roll off part, but it is automatically set to custom and the maximum distance is 10,000
     
  24. JamieLawson

    JamieLawson

    Joined:
    Jul 31, 2014
    Posts:
    12
    when i press play, it automatically creates a custom roll off with the max distance 1000000, and this wont reduce or be deleted. any way to change this?