- Home /
Question by
commodore · Aug 08, 2017 at 05:57 PM ·
webglbrowser communication
Check if Javascript function exists on webpage before calling ExternalCall
I want to do something like this:
if (/*Check if FunctionOnWebpage exists*/) {
Application.ExternalCall("FunctionOnWebpage", args);
}
Right now I get an exception if the web page does not contain the function I'm trying to call from Unity. Wrapping it in a try/catch block doesn't work.
Comment
Answer by · Aug 09, 2017 at 12:40 PM
Try something like this. It will check if FunctionOnWebpage exists, and if it does, call FunctionOnWebpageExists in Unity on a GameObject named "MyGameObject".
Application.ExternalEval("if (typeof FunctionOnWebpage == 'function'){SendMessage('MyGameObject', 'FunctionOnWebpageExists');}");
Then you can make FunctionOnWebpageExists call
public void FunctionOnWebpageExists () {
Application.ExternalCall("FunctionOnWebpage", args);
}