Search code examples
c#audiounity-game-engineunityscript

Changing AudioSource volume


I'm trying to change my AudioSource GameObject volume and as the documentation says it's simply myAudioSourceGameObject.volume = 0.5f.

But, in my script I can't access any field called volume.

So how are you supposed to change your AudioSource's volume through code?


Solution

  • Ok I got it.

    public GameObject go = GameObject.Find("MyGameObjectAudioSource");
    void Update()
    {
         go.GetComponent<AudioSource>().volume = 0.5f;
    }
    

    Thanks everyone for the help.