how would you implement months into your game?

what i am trying to ask is how would you implement time into your game not seconds, minutes, or hours but just months and years.

You really need a bit more context for this. Implementing months and years works the same as implementing seconds, minutes and hours. What effect are you trying to achieve? And what have you tried so far?

I agree with BoredMormon, you need to be more specific, are you using this month and year system as an in-game time system, or do you want to simply make it so that you can tell the date so you could, for example make the player wear an elf hat on Christmas?

well i want it so that after say 3 months the value of a product will change i already have the product and the money system.

2 Answers

2

// Code developed by Michael A. Roberts
// All code is free to use for all private projects.
// If for commerical use, the code is free to use as long as credit is given on publication.

#pragma strict

var seconds : int;
var minutes : int;
var hours : int;
var days : int;
var months : int;
var year : int;

function Start () 
{
seconds = 0;
minutes = 0;
hours = 0;
days = 0;
months = 0;
InvokeRepeating("AddSeconds",1.0,1.0);
}

function Update ()
{
	if (seconds > 59)
	{
	seconds = 0;
	minutes += 1;
	}
	
	if (minutes > 59)
	{
	minutes = 0;
	hours += 1;
	}
	
	if (hours > 24)
	{
	hours = 0;
	days += 1;
	}
	
	if (days > 30)
	{
	days = 0;
	months += 1;
	}
	
	if (months > 12)
	{
	months = 0;
	year += 1;
	}
	
}


function AddSeconds ()
{
seconds += 1;
}

function OnGUI ()
{
GUI.Box(Rect(10,10,30,30), seconds.ToString());
GUI.Box(Rect(50,10,30,30), minutes.ToString());
GUI.Box(Rect(90,10,30,30), hours.ToString());
GUI.Box(Rect(130,10,30,30), days.ToString());
GUI.Box(Rect(170,10,30,30), months.ToString());
GUI.Box(Rect(210,10,30,30), year.ToString());
}

Put this script on your main camera.
Simply have another script call this one and query the int you need to know.

thank you MichaelARoberts!

Note the months aren't quite right, so if you're looking for pin-point accuracy you'd want some sort of bool to check for leap years and the days of the months. My code is just a starting point.

You can use this: