Change volume of category / audio item [SOLVED]

Any general topic can be discussed here

Change volume of category / audio item [SOLVED]

Postby rlf_b » Sun Jul 30, 2017 9:16 pm

Hello there,

I guess I am overseeing something simple due to my noobishness but I can not change the volume of a category / audio item.
As from your demo I learned that it should work like this for a category
Code: Select all
AudioController.SetCategoryVolume( "Music", musicVolume );

Strange thing is that when I use your code like this it does not change the volume (music is written correctly ;))
Code: Select all
AudioController.SetCategoryVolume("music", 10);


So I have got two questions
1. Do you have a clue what I might have missed?
2. How would I address the volume of an audio item by the way?

As for the audio item the documentation says it has a volume field, but how to I change that via C#?

Cheers
Ralf
Last edited by rlf_b on Wed Aug 09, 2017 4:22 pm, edited 1 time in total.
rlf_b
 
Posts: 3
Joined: Sun Jul 30, 2017 8:48 pm

Re: Change volume of category / audio item

Postby clockstone » Wed Aug 09, 2017 2:37 pm

1) volume is between 0 and 1

2)

var audioObj = AudioController.Play( "SomeSFX");
audioObj.volume = 0.5f;
User avatar
clockstone
Site Admin
 
Posts: 16
Joined: Mon Jan 13, 2014 3:18 am

Re: Change volume of category / audio item [SOLVED]

Postby rlf_b » Fri Aug 11, 2017 7:46 am

Oh my goodness I thought I tried using a float. Thanks for the reminder. :)

Now I got something new :P
I would like to fade the volume to a certain level, but only found a complete fade in / fade out method. So I tried using a lerp but this does not seem to have an effect, no matter what numbers I use for speed (0.0001f - 11111)

Code: Select all
vol = Mathf.Lerp(0.4f, 1, Time.time * speed);
AudioController.SetCategoryVolume("music", vol);


Do You have a tip on how I could turn down the volume to 0.4f slowly over 1-2 seconds?
rlf_b
 
Posts: 3
Joined: Sun Jul 30, 2017 8:48 pm

Re: Change volume of category / audio item [SOLVED]

Postby clockstone » Wed Aug 16, 2017 7:44 am

in the script where you play the audio keep track of the returned AudioObject and the current time.
Code: Select all
audioObj = AudioController.Play( "SomeSFX");
timePlay = Time.time;

Then use the Update() function to adjust your volume:
Code: Select all
 audioObj.volume = Math.Clampf01( (Time.time - timePlay) * fadeSpeed);
User avatar
clockstone
Site Admin
 
Posts: 16
Joined: Mon Jan 13, 2014 3:18 am


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron