how to reset time

i’ve written very little local high score script with PlayerPrefab and when i restart Level time doesnt reset. there is the script and if you need you can use :wink:

var points : int;
var targetGuiText : GUIText;
var targetGuiText1 : GUIText;
var Renderer;
private var gldepth = -0.5;
private var startTime = 0.1;
private var tris = 0;
private var verts = 0;
private var savedTimeScale:float;
private var pauseFilter;
private var score : int;

function OnTriggerEnter(hit : Collider)
{
 if(hit.gameObject.tag == "Finish")
 {
 targetGuiText.enabled = true;
 targetGuiText1.enabled = true;
    savedTimeScale = Time.timeScale;
    Time.timeScale = 0;
    AudioListener.pause = true;
    if (pauseFilter) pauseFilter.enabled = true;
 Finish();
 }
}
function Start() {
 targetGuiText.enabled = false;
 targetGuiText1.enabled = false;
}

function Update()
{
 targetGuiText.text = ("Highest Score: " + PlayerPrefs.GetInt("points"));
 targetGuiText1.text = ("My Score is: " +points /2);
  if(Input.GetKey(KeyCode.Home)){
Application.LoadLevel(Application.loadedLevel);
}
 print("I finished in: " +points); 
 Time.timeScale = 1;
}
function Finish(){
//Save this high score da ar damseivebelis dedas sheveci me :D 
if(points > PlayerPrefs.GetInt("points")){
PlayerPrefs.SetInt("points", points);
}
 if(Time.time <= 50) //if you make it before 90 seconds
 {
   points += 60; //add points
 }
 if(Time.time <= 40) //if you make it before 90 seconds
 {
   points += 70; //add points
 }
 if(Time.time <= 30) //if you make it before 90 seconds
 {
   points += 80; //add points
 }
 if(Time.time <= 20) //if you make it before 90 seconds
 {
  points += 90; //add points
 }
 if(Time.time <= 10) //if you made it before 50 seconds
 {
  points += 100; //add points
 } 
}

I deleted your swearing. Please act professionally if you want to be treated with respect.

–

You missed one on line 42.

–

sorry Graham i wrote this script for me and i forgot to delete these words

–

2 Answers

2

Time.time is measured from the start of the game, not the start of the level.

you were right ! now i'm using Time.timeSinceLevelLoad and it works perfectly.

–

Create two new variables, one which will always do the following:

if(timeFollow < Time.time){
     timeFollow++;
     timeUse++;
}

and while timeFollow is always counting up, and never behind, use timeUse as your reset-able variable.

thank you very much. i exactly needed that

–