Veli's Portfolio and Personal Blog
WordPress Profiles to Unity3D?
You read correctly. If you want to have a good community around your game (blogs, forums, etc), you need to find the best tools for that. And for blogging, the best tool is by far WordPress. One of WordPress’ main strengths is the plugin system, which allows you to write your own “hacks” or use plugins made by others without having to edit the core files directly. This ensures a safe and upgradeable framework around which one can build their community.
But enough of that rambling. Here is how I managed to fetch wordpress user profiles into unity.
Unity JS
function Awake() {
GetCookie (display_name);
//This is what you are fetching.
//See http://codex.wordpress.org/Database_Description#Table:_wp_users
}
function GetCookie (query:String){
//Path to your PHP file
var url = "http://domain.com/cookiecheck.php?q=";
var getCookie = WWW(url+query);
yield getCookie; // Wait until the download is done
if(getCookie.error) {
Debug.Log("There was an error getting cookies: "
+ getCookie.error);
} else {
result = getCookie.data;
}
}
function OnGui () {
if (result != null) {
GUI.Label (Rect (10,50,280,20), result);
}
else
GUI.Label (Rect (10,50,280,20), "Waiting for yummy cookies!");
}
Server side PHP cookiecheck.php
$query=$_GET["q"];
require_once('/path/to/your/wp-config.php');
global $current_user;
get_currentuserinfo();
if ('' == $user_ID) {
print("invalid User");
}
else {
print($current_user->$query);
}
It is nothing major, but I spent a good amount of trial and error to get it right. Hopefully this article will save someone else from that trouble. Oh, and big thanks once again to the guys (and gals) at #unity3d@irc.freenode.irc.freenode.net
| Print article | This entry was posted by Veli on 25/05/2009 at 21:12, and is filed under Unity3D. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

