Add Time To Time Bar.

Hello there,

I trying to add timer to my time bar, the way I constructed my timer is by using a “3d plane” and transfrom the postion from “start to end” position, and if the “3d plane” reach the “end” position the game will end.

this is my script :

#pragma downcast
#pragma strict
#pragma implicit

//MASKING GAMEOBJECT//
public var masking : Transform;
//MASKING VECTOR FROM START TO END//
public var start : Vector2 = Vector2.right;
public var end : Vector2 = Vector2.right;
public var addTimer : Vector2 = Vector2.right;
//MASKING TIME SPEED//
public var speed : float;
public var t : float;

function Update () 
{
	TimerDrop ();
}

function TimerDrop ()
{
	t += Time.deltaTime * speed;
	masking.position = Vector2.Lerp (start, end, t);
	
	GameOver ();
}

function GameOver ()
{
	if (masking.position == end)
	{
		print ("gameOver");
	}
}

what I want to do now is, when I push a button the “3d plane” will add value to “A” position as if the time is adding. I tried using this but seems not working:

function AddTimer ()
{
	masking.position += addTimer; 
}

Try

function AddTimer (timeToAddInSeconds:float)
{
	t += timeToAddInSeconds;
}

At the moment you are lerping between start and end with t, so changing masking.position wont affect the result of that and will be overwritten next update.

EDIT: Sorry I was reply on my phone and didn’t finish my sentence.

@JohnnyA,

thanks, solved it. have to change it a bit. I dont know how to access the argument.