An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5.3 KiB

Writing Story Text With Pages

The [Page](@ref Fungus.Page) component defines an area where the story textbox will appear on screen.

  • A Page can display title text, say text and a list of options.
  • Only one page is ever active at a time.
  • The active Page automatically hides when there is no remaining story text or options to display.

How do I add a Page to a Room?

  1. Create an instance of Fungus/Prefabs/Page.prefab and make it a child of the View which it should appear inside.
  2. Resize and position the Page as desired.

How do I control which Page is used to display text?

  1. Ensure there are at least two Page objects in your Room.
  2. Add public Page properties to your Room script and setup references to each Page in the Room.
  3. Use the [SetPage](@ref Fungus.GameController.SetPage) command to control which Page will be used for text rendering.

C# code example

using UnityEngine;
using System.Collections;
using Fungus;

public class MyRoom : Room 
{
	public Page leftPage; // A Page on the left hand side of the Room
	public Page rightPage; // A Page on the right hand side of the Room

	void OnEnter() 
	{
		SetPage(leftPage);
		Say("This text will now display on the left page");
		SetPage(rightPage);
		Say("This text will now display on the right page");
	}
}

Notes

  • If there is only one Page in a Room, Fungus will automatically make this the active Page when entering the Room.
  • If a View has a child Page object, Fungus will automatically make this the active Page after transitioning to that View (e.g. via [SetView](@ref Fungus.GameController.SetView))).
  • If you find that text is not rendering on the Page you expect, you probably need to set the active Page explicitly using the method shown above.

How do I write story text to the active Page?

  1. Use the [Title](@ref Fungus.GameController.Title) command to set the title text to be displayed at the top of the active page.
  2. Use the [Say](@ref Fungus.GameController.Say) command to display a single line of story text and then wait for the player to press the continue button.

C# code example

using UnityEngine;
using System.Collections;
using Fungus;

public class MyRoom : Room 
{
	void OnEnter() 
	{
		Title("The Title"); // Sets the title text
		Say("Hello"); // Writes the story text and waits for player to continue
	}
}

Notes

  • The [Page](@ref Fungus.Page) component defines the area where the story textbox will appear on screen.
  • A Page can display title text, say text and a list of options.
  • Only one Page is ever active at a time.
  • The active Page automatically hides when there is no remaining story text or options to display.
  • The appearance of the title and say text in the Page is controlled via the active [PageStyle](@ref Fungus.PageStyle) object.

How do I create a multiple choice menu on the active Page?

  • Use the [AddOption](@ref Fungus.GameController.AddOption) command to add an option to the current options list.
  • Use the [Choose](@ref Fungus.GameController.AddOption) command to display the current list of options and wait for the player to select an option.

C# code example

using UnityEngine;
using System.Collections;
using Fungus;

public class MyRoom : Room 
{
	void OnEnter() 
	{
		AddOption("Option 1", DoOption1);
		AddOption("Option 2", DoOption2);
		Choose("Pick an option");
	}

	// Delegate method for option 1
	void DoOption1()
	{
		Say("Picked option 1");
	}

	// Delegate method for option 2
	void DoOption2()
	{
		Say("Picked option 2");
	}
}

Notes

  • The [AddOption](@ref Fungus.GameController.AddOption) command takes an optional delegate method to call when the player selects the option.
  • If no delegate method is provided, the menu is dismissed and the next command in the queue is executed.
  • The appearance of the option button is controlled via the active [PageStyle](@ref Fungus.PageStyle) object.

How do I control the appearance of Page text?

  1. Find Fungus/Prefabs/PageStyle1.prefab in the Fungus library
  2. Duplicate and rename this file (e.g. MyPageStyle.prefab)
  3. Modify the style settings in the prefab to adjust the appearance.
  4. Add a public PageStyle property to your Room script and setup a reference to your PageStyle prefab in the inspector.
  5. Use the [SetPageStyle](@ref Fungus.GameController.SetPage) command to change the style used to render Pages.

C# code example

using UnityEngine;
using System.Collections;
using Fungus;

public class MyRoom : Room 
{
	public PageStyle myPageStyle; // Reference to a custom PageStyle prefab

	void OnEnter() 
	{
		Say("This text will display using the default PageStyle");
		SetPageStyle(myPageStyle);
		Say("This text will now display using the custom PageStyle");
	}
}

Notes

  • PageStyle uses standard Unity GUIStyle properties to control the appearance of the text and box background.
  • You can easily change font, text color, bold, italic, etc. for each type of text.
  • Modify the texture and settings in the boxStyle to change the appearance of the background box.
  • Fungus overrides the font size properties for text to ensure consistent text scaling across devices with varying resolutions.
  • Use the xxxFontScale properties to specify font size as a fraction of screen height.