Quantcast
Channel: Questions in topic: "webgl"
Viewing all articles
Browse latest Browse all 2390

Easily getting variable values from WebGL in Browser

$
0
0
I'm developing some 3D interactions in Unity, and they will be embedded in a webpage which will have other interactive components. I'm going to need to communicate between these other components, and I'm wondering if there's an easy way to return a value from Unity into JS variables in the browser. I know I can use SendMessage() to call functions in Unity from external JS, but can I return values from these calls? I don't know how to efficiently do this, so the solution I'm thinking of right now looks like this: Browser: var health; var exp; function GetHealth(){ SendMessage("Player", "GetHealth"); } function ReturnValue(varName, val){ if(varName == "health"){ health = val; } if(varName == "exp"){ exp = val; } //etc. } Unity: public void GetHealth(){ Application.ExternalCall("ReturnValue", "health", health); } This is a really ugly solution that would be ripe with problems. Ideally, I'd like to do something like Browser: function GetHealth(){ return SendMessage("Player", "GetHealth"); } Unity: public int GetHealth(){ return health; } Any ideas?

Viewing all articles
Browse latest Browse all 2390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>