Hello everyone!

When the 1st scene starts the timer capsule object starts to shrink while time is running out and when time ends a game over texture appears on the screen and then u go back to main menu. When you click on play the 1st scene loads again but the timer capsule object is still shrank (scale.y=0). I tried to set again my object with the default scale and color on Start() but it doesn’t work. :frowning:

How do i set back the capsule object to its first size everytime i load the scene?

The js script called Begin is attached to MainCamera object and it is shown below:

public var capsuleTimer: GameObject;
public static var flagTxtr:boolean = false;
public static var endTimer:int =0;
public var gameOverClip: AudioClip;
public var hasPlayed:boolean=false;
public var disable_cTmr:boolean=false;

function Update(){

if(disable_cTmr == false){
	var cTmr= capsuleTimer.Find("capsuleTimer");
	cTmr.renderer.material.color = Color( 0/255.0, 205/255.0, 102/255.0, 0);
	var timer:int = 200;
	var timer_:int;
	var TimeSpeed = 50;

	timer_ = timer - (Time.time * TimeSpeed);
	cTmr.transform.localScale.y = Mathf.Clamp(timer_, 0, 200);
	endTimer = timer_;
	var light_ = oDLight.Find("Directional light_1");

	if(timer_ <= 100)
		cTmr.renderer.material.color = Color( 255/255.0, 165/255.0, 0/255.0, 0);
	if(timer_ <= 50)
		cTmr.renderer.material.color = Color( 238/255.0, 0/255.0, 0/255.0, 0);
	if(timer_ == 0){
		flagTxtr=true; // make gameover texture visible by setting variable flagTxtr to true
		if(hasPlayed == false){
			//Debug.Log("Game Over!");
			audio.PlayOneShot(gameOverClip); 
			hasPlayed = true;
		}	
		light_.light.enabled = false;
		Invoke("LoadGameOver",10);
	}
}
	
}

function LoadGameOver(){ //go to High score Scene (from there u can move to main menu and then click on play where my game scene loads
		Application.LoadLevel ("High_Score");  
}

You can just replace Time.time with Time.timeSinceLevelLoad. That is the time since the last level(scene) was loaded.

//........
timer_ = timer - (Time.timeSinceLevelLoad * TimeSpeed);
//........

The Reason is Time.time is number seconds passed since start of the game it doesnt change while switching scenes

So to fix it
add these codes

var StartTime:float =0;

function Start(){
StartTime = Time.time;
}

function Update(){

//your code
 timer_ = timer - (StartTime * TimeSpeed);

//rest of code
}