A step-by-step tutorial: sample code included!
Context for this Tutorial
Carnival Craze is a 2D iPhone game we're submitting to the app store this week. It's programmed in Unity's 3D engine with an orthographic 2D camera. In the game, the Fortune Teller gives you any of a number of fortunes. You can post your favorite ones to your Facebook wall for all you friends to see. This tutorial shows how to do this, with all the code you need.
Writing to Player Prefs
In the game, each fortune has a button saying “POST THIS FORTUNE TO YOUR WALL.” In script, we write to PlayerPrefs when that button is pressed. We're naming this PlayerPref “Fortune” and the associated value is whatever the string currentFortune is holding. When the game is running on device, this adds a key-value pair to NSUserDefaults. The key is “Fortune” and the value is “Plan for many pleasures ahead.” in this instance.
var invisible : GUIStyle;
private var currentFortune : String = "Plan for many pleasures ahead.";
function OnGUI()
{
if( GUI.Button( Rect( 100, 260, 120, 40 ), "", invisible ))
{
PlayerPrefs.SetString("Fortune", currentFortune);
}
}
Continue reading "Add Facebook Connect to a Unity iPhone Game" »