Unity WebPlayer to Javascript to Facebook

Today, I was going to introduce some prototype screenshots of our next game, however over the last few days I’ve found myself getting pulled back to Mash ‘Em Marbles after it was finally accepted for the Facebook Directory.

The general feedback from users suggested that it needed to be a more social experience, so I decided to take a look at how to do just that.

Facebook recently created the Graph API- amethod of accessing Facebook data using URLs. For instance, you can view information about yourself by going to “http://graph.facebook.com/me” (Don’t worry, although the url is that simple, the software accessing it has to ask facebook for an “access key” before making the request- so you can’t just go poking around your friends data like that.

Which brings me, finally, to my latest bit of work:

Aquick way to interface Unity with a Website- and Facebook:

I will provide an example project shortly, but essentially the project folder includes:

appdata.php – This PHP file contains your Facebook keys and application name

index.php - This file is the page that is served to Facebook, and to the end user.

title.png – This is your application logo.

Unityapp.unity3D – This is the unity application.

index.php takes care of the initial add of the application, and if the application is alreay added (and the user has given it permission), will display the full application page. In our instance, it loads a Unity Webplayer application.

index.php then sends messages to the unity3D plugin via Javascript. Unity3D can call functions from within the Javascript code on the webpage by using it’s ExternalCall function. Get this:

In your webpage, you have functions GetScore, SubmitScore etc.  You can call these functions from within Unity using ExternalCall(“GetScore”); , now, if GetScore is coded to send a high score to Unity, you have a way of controlling data flow between your website and Unity.

Without going into too much more detail, this all works reallly well and is somewhat easier than I made it sound above. The library I have written will take care of  the more difficult tasks for you.

Mash ‘Em Marbles is currently in private testing for friends-based high scores. Once that’s completed, all I’ll have to do is make it annoy all your friends when you get a high score and we’re good to go!


Switch to our mobile site