As part of our internship we've been tasked with creating a business application using Unity WebGL. After reading on interactions between JS and the C# code we're in a corner.
We're trying to get back a list from C# to populate a Select on our webpage and we just don't know how to do it. We've followed the Unity documentation and can easily communicate and get back data to use in our C# from our webpage.
We can't however access C# data in our browser. SendMessage() method does not allow returns.
Here's our code so far
index.html
<select id="wallsSelect"></select>
jsfile
function getWallsList() {
//function is called at the creation of our object
var wallsSelect = document.getElementById("wallsSelect");
index = 0;
var wallsList = gameInstance.SendMessage('WallCreator', 'GetGameObjects'); //would like to get back our list of walls and populate our Select with it
for (item in wallsList) {
var newOption = document.createElement("option");
newOption.value = index;
newOption.innerHTML = item;
wallsSelect.appendChild(newOption);
index++;
}
C# code finally
public List<string> GetGameObjects()
{
List<string> goNames = new List<string>();
foreach (var item in goList)
{
goNames.Add(item.name);
}
Debug.Log("Accessed GetGameObjects method. GameObject count = " + goNames.Count.ToString()); //The object is instanciated and return the right count number so it does work without a problem
return goNames;
}
Yes we did check https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html and I've made numerous research and found some interesting resources that I can't wrap my head around being too inexperienced, for example http://tips.hecomi.com/entry/2014/12/08/002719
To conclude, I would like to point out it's our first "real world" project and Unity-WebGL is quite an experience to play with seeing the lack of documentation.