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.

Question How can I get a javascript reference to my WebGL builds' WebAudio?

Discussion in 'Web' started by a1creator, Apr 6, 2023.

  1. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    23
    After much research I have found that WebGL builds use a HTML component to play the audio. This is not a problem at all, but I have no idea how to reference it.

    I need this because I have made an audio slider that I would like to be able to control the game's main volume via the HTML Audio.

    My idea is to do something like this with the reference:
    Code (JavaScript):
    1. document.getElementById("????").volume = _sliderValue;
    I have gone through many, many posts discussing how to handle audio in js/html and I think this is how it can be done, but I just don't know how to get the reference to the WebGL player's Audio component.

    If anyone knows how - or knows another way to do this - please do reply!
    Thank you for taking the time to read this:D