Pause Time.time?

Ok so I have a script where I have an int: score, and it’s equal to Time.time * 150. What I want to do is when my character hits the ground, the score pauses at the value it was at when it hit the ground.

Here is my code:


    #pragma strict
    
    var score : int = 0;
    
    var style1 : GUIStyle;
    
    function Start () {
    
    }
    
    function Update () {
    	score = Time.time * 150;
    }
    
    function OnTriggerEnter(collisionInfo : Collider){
        if(collisionInfo.gameObject.tag == "Player"){
            Debug.Log("You failed!");
            //Pause score at current value here
        }
    }
    
    function OnGUI(){
    	
    GUI.Label(Rect(100,100,200,40), "" + score.ToString(), style1);	
    	
    }

Note that Time.time contains the absolute time since the beginning of your game. So your player can’t start over, without having an ever increasing initial score. What you want to do instead is using a relative time:

var startTime:float=0.0;
function Start(){
    startTime=Time.time; // store current time. you could also move this to when the player jumps or whatever
}

// no Update computation necessary

function OnTriggerEnter(collisionInfo : Collider){
    ....
    // compute actual score
    finScore=(Time.time-startTime)*150;
    ...