- Home /
C# webGL and browser communication
Hi, I'm just trying to get a untity webgl player to browser communication working.
I would be very glad if somebody could explain to me where I need to include the SendMessage function to get the webGLPlayer and browser communication working.
What I actually want to do is to send a float value from an html slider component to the unity webGLPlayer and finally to my C# script to change the color of an object.
That's the slider in the index.html from the webGL Unity build process:
<div class="input-group">
<input id="rInput" onclick="ChangeValue()" type="range" min="0" max="255" step="1" />
</div>
the js function inside of the index.html file:
function ChangeValue(red)
{
var r = document.getElementById("rInput").value;
red = parseFloat(r/100.0);
SendMessage("GameObject","ChangeColor",red);
}
Thtat's the C# script with the ChangeColor() function:
public float r = 2.0f;
void ChangeColor(float r)
{
Renderer rend = GetComponent<Renderer> ();
rend.material.shader = Shader.Find ("Standard");
rend.material.SetColor("_Color", new Color(r, 1.0f, 1.0f, 1.0f));
}
void Update () {
ChangeColor (r);
}
So the slider component the JS Script and the C# script itself is working. But the SendMessage function just doesn't work because it's declaration from the webGL.js is not accessable to the index.html where I try to get use of it. I would be very glad if somebody could explain to me how to get this working.
Greetings Carl