I want to build a unity WebGl project that by clicking a button or switching scene inside unity web player, corresponding 'div' should be displayed in the .html file. For instance, switching to Scene02, a div with id "Scene02" containg introductions and images about it would be showned, and other div would be "deactivated".
I have wrote a .jslib as Plugins capturing all these Introduction divs in my custom index.html template, and called it inside Unity.
in .Jslib
> function showDiv(idInfo) {
var sel = document.getElementById('divLinks').getElementsByTagName('div');
for (var i = 0; i < sel.length; i++) {
sel[i].style.display = 'none';
}
document.getElementById(idInfo).style.display = 'block';
}
in Unity
> currentScene = SceneManager.GetActiveScene();
string divArrayID = "divLinks";
if (currentScene.name != null) { ShowDiv(currentScene.name, divArrayID); }
However the showDiv function above seemed to fail to find the Element "divLinks", I wonder now if this .jslib file knows which .html file to look at while compiling or you have to manually add some dependcies for that? Or is there a workaround?
I might be missing something very obvious, but I appreciate any advice and explanation.
↧