- Home /
A Question about Dot Syntax...
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);
}
};
Answer by Eric5h5 · May 27, 2013 at 06:02 PM
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.
Thanks a lot, but I wanted to make it so that after 5 seconds it becomes transparent... So how do I do that? Also, I thought Time.time was the amount of time since the game started, but you said it doesn't do anything... Now I'm confused...
I'm still confused... Is this what you want me to do?
function Start () {
var one : GameObject = GameObject.Find("/Health/1");
}
function Invoke () {
switch(Time.time) {
case 5:
one.guiTexture.color.a = 0.0;
}
};
No, not at all. Look up Invoke in the Unity documentation.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103019im_/https://answers.unity.com/themes/thub/images/avi.jpg)