I can call a javascript defined on the webpage and that works fine. But I cannot Call a function in my gameobject from the webpage.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class APIManager : MonoBehaviour
{
static public APIManager instance;
private string PageData;
void Awake()
{
DontDestroyOnLoad(gameObject);
instance = this;
}
void Start()
{
Application.ExternalCall("SendUnityFBInfo");
}
void RecieveInfo(string data)
{
Debug.Log(data);
PageData = data;
}
void OnGUI()
{
GUI.depth = 0;
GUI.Label(new Rect(0, 0, 200, 20), "Data:" + PageData);
}
}
<script type="text/javascript">
function GetUnity()
{
if (typeof unityObject != "undefined") {
return unityObject.getObjectById("unityPlayer");
}
return null;
}
if (typeof unityObject != "undefined") {
unityObject.embedUnity("unityPlayer", "WebPlayer.unity3d", 800, 600);
}
function SendUnityFBInfo()
{
var response = "test";
alert(response);
var unity = unityObject.getObjectById("UnityContent");
unity.SendMessage("APIManager", "RecieveInfo", response);
}
</script>
When I load my game i get the alert of “test” but in unity window my label just shows Data: