- Home /
child script and child source
Hi guys,
I have an empty game object (namely, music), which contains an audio source and a script. Is there an easy way to access the audio source.volume from the script, even though they share a parent? Or do I have ot either A) create a public audioSource object and reference the source that way? When I use gmaeObject. or this., there appears to be no available reference to the audioSource.
Thanks! Znaijcakc
Answer by JustAnotherDude · Jan 08, 2014 at 09:51 PM
The script and audiosource being on the same GameObject you can access it on the script by using :
this.GetComponent<AudioSource>().volume = 0.5f;
If you need you can store the AudioSource in a variable too
AudioSource audio = this.GetComponent<AudioSource>();
audio.volume = 0.5f;
Your answer
Follow this Question
Related Questions
Accessing delta-rotation values? 1 Answer
Volume Slider 0 Answers
What is the exact equation being used for sound volume? 0 Answers