Hello, im a begginer javascript programer and i mad a game clock. it shows 24 real life minutes whic is a day in my future game. You can pause it set the morning time and the dawn time.
Now i got two booleans, setToDayTime and setToNigthTime and i want these to set the clock to the morning time and the dawn time and continue the counting from there but i havent managed to make it in the past two days.
Can someone help me out?
#pragma strict
var mutato1 : GameObject;
var mutato2 : GameObject;
var mutato3 : GameObject;
var mutato4 : GameObject;
var dayTimeStartHour : int = 6; //morning start
var dayTimeEndHour : int = 18; //morning end
var setToDayTime : boolean = false; //set clock to morning start
var setToNigthTime : boolean = false; //set clock to morning end
var isItDayTime : boolean = false;
var pauseGameTime : boolean = false; //pause game time
var displayTime : float; //actual time displaying
var difference: float; // to pause game time
private var ido2 : float;
function aniSprite ( spriteObject : GameObject, columnSize : float, rowSize : float, type:String, index : int) // animating spirtes 0-9
{
var minute1 = index % 10;
var minute2 = (index/10) % 6;
var minute3 = (index / 60) % 10;
var minute4 = (index / 600) % 2.4;
if(type == "font1") index = minute1;
if(type == "font2") index = minute2;
if(type == "font3") index = minute3;
if(type == "font4") index = minute4;
var size : Vector2 = Vector2 ( 1.0 / columnSize, 1.0 / rowSize ); // find scale to show on poly
var offset : Vector2 = Vector2(index * size.x ,1);
spriteObject.renderer.material.mainTextureOffset = offset; // apply the offset amount to the correct sprite sheet object
spriteObject.renderer.material.mainTextureScale = size; // apply the scale amount to the correct sprite sheet object
}
function Update ()
{
var ido : float = Time.time - ido2;
if(!pauseGameTime) //pause gametime
{
displayTime = ido - difference;
ido -= difference;
}
if(pauseGameTime) //continue gametime
{
difference= ido - displayTime;
}
if( ido >= 1440) //reset timer from 1440 seconds (24min) to 0
{
ido2 = Time.time - difference;
}
if(displayTime >= dayTimeStartHour * 60 && displayTime <= dayTimeEndHour * 60)
{
isItDayTime = true;
}
else
{
isItDayTime = false;
}
if(setToDayTime)
{
displayTime = dayTimeStartHour * 60;
setToDayTime = false;
}
if(setToNigthTime)
{
displayTime = dayTimeEndHour * 60;
setToNigthTime = false;
}
aniSprite (mutato1, 10, 1, "font1", displayTime);
aniSprite (mutato2, 10, 1, "font2", displayTime);
aniSprite (mutato3, 10, 1, "font3", displayTime);
aniSprite (mutato4, 10, 1, "font4", displayTime);
}