INFINITY SERIES

SCRIPTS & TUTORIALS
First Person RPG | Time Control
This is a package that includes a few scripts and a demo scene. The "Time Controller" object in the demo will keep track of in-game time, but only while the menu is inactive and the "t" button is not being pressed. The concept is that while we want the in-game time to progress as the player explores the world, we want it to pause while the player is using the menu, or for other reasons.

Download Unity Package

Video Tutorial


Script(s)
timeControl.js
#pragma strict

static var timeCode		: float				= 0.0;					// Game Timecode
static var callForPause		: int				= 0;					// Other scripts calling for Pause this frame

var inGameTimeMultiplier	: float				= 30;					// How much faster is in game time vs. real life?

static var gameSecond		: float				= 0.0;					// In game second count
static var gameMinute		: int				= 0;					// In game minute count
static var gameHour		: int				= 8;					// In game hour count
static var gameDay		: int				= 1;					// In game day count
static var gameMonth		: int				= 5;					// In game month count
static var gameYear		: int				= 3293;					// In game year count

static var secondsPerMinute	: int				= 60;					// In game seconds per minute
static var minutesPerHour	: int				= 60;					// In game minutes per hour
static var hoursPerDay		: int				= 24;					// In game hours per day
static var daysPerMonth		: int				= 28;					// In game days per month
static var daysPerWeek		: int				= 7;					// In game days per week
static var monthsPerYear	: int				= 12;					// In game months per year

function Start () {

}

function LateUpdate () {
	if (callForPause == 0)
		UpdateTime();
}

function UpdateTime(){
	timeCode	+= Time.deltaTime;							// Increase timecode
	gameSecond	+= Time.deltaTime * inGameTimeMultiplier;				// Increase game second counter

	if (gameSecond >= secondsPerMinute)							// We've gone over a full minute
	{
		gameMinute	+= 1;								// Increase minute counter
		gameSecond	-= secondsPerMinute;						// Reset second counter
	}
	if (gameMinute >= minutesPerHour)							// We've gone over a full Hour
	{
		gameHour	+= 1;								// Increase hour counter
		gameMinute	-= minutesPerHour;						// Reset minute counter
	}
	if (gameHour >= hoursPerDay)								// We've gone over a full Day
	{
		gameDay		+= 1;								// Increase Day counter
		gameHour	-= hoursPerDay;							// Reset Hour counter
	}
	if (gameDay >= daysPerMonth)								// We've gone over a full Month
	{
		gameMonth	+= 1;								// Increase Month counter
		gameDay		-= daysPerMonth;						// Reset Day counter
	}
	if (gameMonth >= monthsPerYear)								// We've gone over a full Year
	{
		gameYear	+= 1;								// Increase Year counter
		gameMonth	-= monthsPerYear;						// Reset Month counter
	}
}

----------------------------------------------------------
YOU ARE FREE TO USE THESE SCRIPTS IN YOUR PROJECT IN ANY WAY YOU WOULD LIKE!
IF YOU HAVE PURCHASED OUR MODELS TO USE IN YOUR PROJECTS, WE THANK YOU VERY
MUCH FOR YOUR SUPPORT!  WITHOUT IT, WE COULDN'T KEEP MAKING MORE KILLER
ASSETS FOR YOUR GAMES.

http://www.InfinityPBR.com
----------------------------------------------------------
pauseWhileActive.js
#pragma strict

function OnEnable() {
	// While any object with this script is active, recording time is paused.
	timeControl.callForPause	+= 1;
}

function OnDisable(){
	// This will allow time to be recorded again.  However, if other objects
	// also have this script, it will still be paused.
	timeControl.callForPause	-= 1;
}

----------------------------------------------------------
YOU ARE FREE TO USE THESE SCRIPTS IN YOUR PROJECT IN ANY WAY YOU WOULD LIKE!
IF YOU HAVE PURCHASED OUR MODELS TO USE IN YOUR PROJECTS, WE THANK YOU VERY
MUCH FOR YOUR SUPPORT!  WITHOUT IT, WE COULDN'T KEEP MAKING MORE KILLER
ASSETS FOR YOUR GAMES.

http://www.InfinityPBR.com
----------------------------------------------------------
debugDisplay.js
#pragma strict

var timeDisplay		: GameObject;
var months			: String[];					// Array of month names

function Start () {
	
}

function Update () {
	UpdateTimeDisplay();

	if (Input.GetKeyDown("t"))
		timeControl.callForPause	+= 1;
	if (Input.GetKeyUp("t"))
		timeControl.callForPause	-= 1;
}

function UpdateTimeDisplay(){
	var timeString		: String;
	timeString						= FixedMonth() + " " + timeControl.gameDay + ", " + timeControl.gameYear;
	timeString						= timeString + " " + FixedHour() + ":" + FixedMinute() + "" + Meridian();
	timeString						= timeString + "\n" + timeControl.timeCode;
	timeDisplay.GetComponent(UI.Text).text		= timeString;
}

function FixedMonth() : String {
	return months[timeControl.gameMonth];
}

function FixedHour() : int {
	var fixedHour	: int;
	if (timeControl.gameHour == 0)
		fixedHour					= 12;
	else if (timeControl.gameHour > 12)
		fixedHour					= timeControl.gameHour - 12;
	else
		fixedHour					= timeControl.gameHour;
	return fixedHour;
}

function FixedMinute() : String {
	var fixedMinute	 : String;
	if (timeControl.gameMinute < 10)
		fixedMinute		= "0" + timeControl.gameMinute;
	else
		fixedMinute		= "" + timeControl.gameMinute;
	return fixedMinute;
}

function Meridian() : String {
	var meridian	: String		= "am";
	if (timeControl.gameHour >= 12)
		meridian					= "pm";
	return meridian;
}

----------------------------------------------------------
YOU ARE FREE TO USE THESE SCRIPTS IN YOUR PROJECT IN ANY WAY YOU WOULD LIKE!
IF YOU HAVE PURCHASED OUR MODELS TO USE IN YOUR PROJECTS, WE THANK YOU VERY
MUCH FOR YOUR SUPPORT!  WITHOUT IT, WE COULDN'T KEEP MAKING MORE KILLER
ASSETS FOR YOUR GAMES.

http://www.InfinityPBR.com
----------------------------------------------------------