From 922922c22266419c09090467a6415cf2fe2e02a2 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 25 Jun 2014 22:15:55 +0100 Subject: [PATCH] Room visit count now persists between scene loads. --- Assets/Fungus/Scripts/Room.cs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Assets/Fungus/Scripts/Room.cs b/Assets/Fungus/Scripts/Room.cs index e770aed9..c6953858 100644 --- a/Assets/Fungus/Scripts/Room.cs +++ b/Assets/Fungus/Scripts/Room.cs @@ -15,17 +15,34 @@ namespace Fungus */ public abstract class Room : GameController { + string GetVisitVariableKey() + { + return "_visits." + gameObject.name; + } + + /** + * Returns the number of times the player has visited this Room. + * The Room game object name is used to track the visit count and so must be unique in the game. + */ + public int GetVisitCount() + { + return Variables.GetInteger(GetVisitVariableKey()); + } + /** - * Number of times player has entered the room + * Sets the number of times the player has visited this Room. */ - public int visitCount; + void SetVisitCount(int count) + { + Variables.SetInteger(GetVisitVariableKey(), count); + } /** * Returns true if this is the first time the player has visited this room. */ public bool IsFirstVisit() { - return (visitCount == 0); + return GetVisitCount() == 0; } // Automatically draws arrows to other Rooms referenced in public properties @@ -146,7 +163,10 @@ namespace Fungus // It is the responsibility of the client room script to set the desired active view & page in the OnEnter method. game.commandQueue.CallCommandMethod(game.activeRoom.gameObject, "OnEnter"); + // Increment visit count for this Room + int visitCount = GetVisitCount(); visitCount++; + SetVisitCount(visitCount); } } } \ No newline at end of file