Working with Fungus

I’ve done some playing around with Twine before, and while I love the simplicity of the platform, the software isn’t very stable or fun to use. I’ve been getting my head around C# and Unity3D, and was thinking that it’d be amazing to be able to make interactive fiction with a robust platform like Unity. A quick bit of Googling and I found Fungus by Snozbot. If you don’t know them, Snozbot is a small crowd of game developers based in Dublin, making a lot of small, polished games. Fungus is a library for Unity3D that’s designed to make it easier to create interactive stories.

Flicking through the thorough documentation I got stuck into setting up a scene. It requires rethinking how you work within Unity, but the library seems very well-thought-out so far.

If you’d like to see how the following code plays out, take a look at the game as it is right now, it’s available in the web player or as a Mac OS X or Windows download.

[codebox]using UnityEngine;
using System.Collections;
using Fungus;

public class FirstScene : Room {

public Page GoodGuy;
public Page BadGuy;
public string levelToLoad;

// Use this for initialization
void OnEnter ()
{
SetPage(GoodGuy);
Say(“Uh…ugh. Where am I?”);
SetPage(BadGuy);
Say(“Don’t worry, you’re safe.”);
SetPage(GoodGuy);
Say(“Why can’t I see anything? Agh, I can’t move!”);
SetPage(BadGuy);
Say(“Your hands are tied and I put a hood over your head.”);
Wait(2);
SetPage(GoodGuy);
Say(“Wait. Did you say I’m safe?”);
SetPage(BadGuy);
Say(“Yes.”);
SetPage(GoodGuy);
Say (“I don’t feel safe.”);
SetPage(BadGuy);
Say (“You’re not. I lied.”);
Wait (1);
Say (“There’s going to be a lot of that.”);
SetPage(GoodGuy);
Say (“Please, I’m a father. You have to let me go.”);
SetPage(BadGuy);
Say (“Wah wah wah, I’m a father! Who cares?”);
// Fade down here?
Call(LoadLevel);
}

private void LoadLevel()
{
Application.LoadLevel(levelToLoad);
}
}[/codebox]

As you can see, there’s no Start() or Update() methods, those aren’t necessary with this library. Instead, we just go straight to OnEnter () and use Say() instead of getting into OnGUI functions.

There is definitely a learning curve, when I first put the code together I thought I could just call the next level by putting in the line Application.LoadLevel(levelToLoad) but that would just skip all of the scene and go straight to the next level. Then I tried encapsulating it in its own function as LoadLevel() but that didn’t work either. In the end I referred back to the documentation and saw that in order for the command to be processed by the command queue they’ve built for their system, you need to refer to other member functions with the Call() command, hence the Call(LoadLevel) at the end of the OnEnter() method.

It’s early days yet, but this is a powerful way to avoid all that messy GUI stuff in Unity.

Leave a Reply

Your email address will not be published. Required fields are marked *