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

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;