question

bamboodude avatar image
bamboodude asked

Login to Kongregate: call Java from c# script

I am making a game in Unity and set up Playfab. LoginwithCustomId etc. all works fine. I tried integrating Kongregate API by follwing this guide: https://api.playfab.com/docs/tutorials/landing-players/kongregate-unity . Everything works until the script for the "KongregateHandler". When copying the script, I get a few errors becomes some things are obsolete:

Application.ExternalEval(
"if(typeof(kongregateUnitySupport) != 'undefined'){" +
" kongregateUnitySupport.initAPI('Kongregate', 'OnKongregateAPILoaded');" +
"} else {" +
" console.error('No unity support!');" +
"};"
);

//and further below

Application.ExternalEval(string.Format("console.log('{0}')", message));

I am referenced to this page https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html and I did the examples there and succesfully tested them, but I have no clue how to call those functions above, I don't know any java and can't find a solution. Any help would be greatly appreciated.

unity3d
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JayZuo avatar image
JayZuo answered

Although Application.ExternalEval is now obsolete, but as you can see, this will just gives you a warning not an error. It's the legacy way of calling JavaScript code from Unity, you should still be able to use it with no problem. And in Kongregate documentation, it also suggest using the Application.ExternalCall and Application.ExternalEval functions from within your Unity application.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bamboodude avatar image bamboodude commented ·

Thank you very much! I'm an idiot, tried to modify the code etc. but never tested the original code with an uploaded build. Everything works perfectly now!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.