Some help with time bar

I need to put a bar (GUI) to decrease value when the player hit a poison floor.

The script works but it is very fast. Any suggestions?


var bar : boolean;
var maxlife = 100;
var currlife = 100;

function Start(){
bar = false;

function Update(){
	if (bar == false){
	currlife = 100;

	currlife -= 1.0 * Time.deltaTime;

function OnTriggerEnter(){
bar = true;
function OnTriggerExit();
bar = false;

Another doubts:

  • How to memorize the lat value os de currlife variable?
  • How to change the (rectangle) color from script?

Thanks a lot

If it is too fast then throttle it!

currlife -= 1.0 * Time.deltaTime * 0.1; // 1/10th as fast..

-The script works but it is very fast
*if you decrease the value of 1.0 to something smaller, it’ll decrease slower.

-How to memorize the lat value os de currlife variable?

if (bar == false){ currlife = 100; }

if you delete this, it will remember the last value.

-How to change the (rectangle) color from script?
use a GUIStyle to set a background texture on box

The script shown seems incorrect - there’s a { missing on OnTriggerExit function. The rest seems ok - currlife should be decreased 1.0 units per second.

I suggest you to use a “static” variable to store player data. You should put all player related variables in one script, declare them as static and assign the script to the player - for instance:

static var currlife: float;

The static variables in this case can be accessed by any js script:

  Control.currlife -= Time.deltaTime;

If you have problems trying to access js static variables from C# scripts, put the C# scripts in a new folder at the root level of your project, and they will “see” the js globals.

Refering to time, I changed the command to

currlife -= 0.1 * Time.deltaTime;

currlife -= Time.deltaTime * 0.1;

and nothing happens. What´s wrong?