Power up timer...

hi … i have made my power up part, when i collide with my power up object magnet, it starts collecting coins(like magnet catcher) and after 12 seconds it backs to normal. what i am looking for is just to show a power up bar which like health bar which show for the time we assign, like 12 seconds and after that disappear. … like in subway surfer,like this alt text or minnion rush circle power up bar … i have searched but i am not understanding it very well … i have tried to applied this one … but its not working like i want :frowning: … kindly help me please … i ll be more than glade … :cry: … its driving me crazy …

#pragma strict

    var barDisplay : float = 0;
    internal var pos : Vector2 = new Vector2(20,40);
    internal var size : Vector2 = new Vector2(20,50);
    var EmptyS: GUIStyle;
    var FullS: GUIStyle;
    
    var progressBarEmpty : Texture2D;
    var progressBarFull : Texture2D;
    var progressBar : boolean = false;
         
    function OnGUI()
    {
    if (progressBar==true)
    { 
    // draw the background:
    GUI.BeginGroup (new Rect (pos.x, pos.y, size.x, size.y));
    GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty);
     
    // draw the filled-in part:
    GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
    GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
    GUI.EndGroup ();
     
    GUI.EndGroup ();
     
    	}
    }
     
    function Update()
    {
    // for this example, the bar display is linked to the current time,
    // however you would set this value based on your desired display
    // eg, the loading progress, the player's health, or whatever.
    barDisplay = 1 -Time.time* 0.05;
    }

Here is a bit of code for one way of doing this behavior. Just something to get you started since I suspect you are visualizing something specific. Start a new scene, attach the following script to an empty game object, drag a texture you want to reveal over time to the ‘tex’ variable, hit play, and click the mouse button.

#pragma strict
 
var tex  : Texture;
var tex2 : Texture;
 
var percent = 1.0;
var showPowerUp = false;
 
function Update() {
    if (!showPowerUp && Input.GetMouseButtonDown(0)) {
       PowerUpOverTime(10.0);
    }
}
 
function OnGUI() {
    if (showPowerUp) {
       GUI.DrawTexture(Rect(0,0, tex.width, tex.height), tex2);
       GUI.DrawTextureWithTexCoords(Rect(0,0, tex.width * (1.0 - percent), tex.height), tex, Rect(0,0,1.0 - percent,1));
    }
}
 
function PowerUpOverTime(time : float) {
    var timer = 0.0;
    showPowerUp = true;
    while (timer < time) {
       percent = timer / time;
       timer += Time.deltaTime;
       yield;
    }
   showPowerUp = false;
}