Am I using it right? I’m trying to make the health bar disappear after 5 seconds, but my script isn’t running, and I know something’s wrong. Can you help?
Here’s my code (it’s UnityScript):
var time: float = Time.time;
var one : GameObject = GameObject.Find("/Health/1");
function Update () {
switch(time) {
case 5:
one.guiTexture.color.a(0.0);
}
};
No, you have to assign a value.
one.guiTexture.color.a = 0.0;
Some other problems: you assign Time.time to a variable called time but then never do anything with it, so time will always be 0.0. Why do you have that at all, instead of just using Time.time? However even if you removed that variable, you can’t use Time.time in a switch statement, since it’s highly unlikely it will ever be exactly 5.0. Also the “one” variable should only be declared outside a function; running code such as GameObject.Find should always be done inside a function, such as Start or Awake. Also “one” is not a good variable; use something more descriptive.
By the way, it would be a lot easier just to use Invoke for this anyway instead of Update.