Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

(WebGL) Activate Unity Functions with HTML/Javascript

$
0
0
I know similar questions to this have been asked before, but after following other answers/examples exactly, I still cannot get this working. According to http://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html you can communicate between the Unity WebGL app itself and the HTML of the container page using `SendMessage ('MyGameObject', 'MyFunction', 'foobar');` I have set up an extremely basic scene for testing- a camera, directional light, and a cube with a script "TestFunction" attached to it. TestFunction contains: using UnityEngine; using System.Collections; public class TestFunction : MonoBehaviour { public bool active; void Start() { active = true; } // Update is called once per frame void Update () { if (active == false) this.gameObject.SetActive (false); } } My index.html file is the standard Unity WebGL template, along with two additions: and Upon loading the page on my MAMP web server, waiting for the Unity WebGL application to fully load, and then clicking on my Test Function button, nothing in the app happens (cube should be toggled inactive). The JavaScript console displays: UnityLoader.js:141 SendMessage: object Cube does not have receiver for function TestFunction! (index):37 Should be calling a function in Unity So that shows that the button onClick() event is happening, however I can't seem to get the actual function to work properly. What am I doing wrong / missing here?

Viewing all articles
Browse latest Browse all 1875

Trending Articles



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