How can i increase Rect.width when i pick up something ?

I was making the pick up props can increase the time that in the countdown of the script , but I don`t know how to pick up an object then increase time. I hope anybody can help me.thanks.

var myRect : Rect; 
var myText : Texture; 
function Start() 
{ myRect = Rect(0,0,256,32); 
} 

function Update() 
{ 
  // Example way to change bar length 
 myRect.width -= Time.deltaTime; 
  if (myRect.width < 0) { 
    myRect.width = 0; 
  } 
} 

function OnGUI() 
{ 
  GUI.DrawTexture(myRect, myText); 
}

And how can i change the increase Value like increase 10 in onetime?the script is from the tutorials.

static var Count : int = 0;
var CollectSound : AudioClip;

function OnControllerColliderHit(hit:ControllerColliderHit){
if(hit.gameObject.tag == "gem"){
Destroy(hit.gameObject);
		//this adds 1 to the variable called 'Count'
		Count++;		audio.PlayOneShot(CollectSound);
	}	
	
}

You could make a variable called remainingTime, and do something like this

var myRect : Rect;
var myText : Texture;
var remainingTime : float;

var startTime = 60.0;
//(assuming you want to start with 60 seconds)

//the width (in pixels) that represents one second
var WIDTH_PER_SECOND = 2;

function Start()
{ myRect = Rect(0,0,256,32);

//begin with ‘startTime’ seconds on the clock
remainingTime = startTime;

}

function Update()
{
remainingTime -= Time.deltaTime;

myRect.width = remainingTime * WIDTH_PER_SECOND;
if (myRect.width < 0) {
myRect.width = 0;
}
}

function OnGUI()
{
GUI.DrawTexture(myRect, myText);
}

function OnControllerColliderHit(hit:ControllerColliderHit)
{
if(hit.gameObject.tag == “gem”){
Destroy(hit.gameObject);

//add 5 seconds to the timer
remainingTime += 5;
}
}

I don’t know if that’s what you were looking for, but I hope it helps!

WOW!It works perfectly!Thank you to help me a lot. :lol: