Game Development Reference
In-Depth Information
}
}
Here, we check whether the current time passed in-game is greater than the value of
the
SpawnTime
variable plus the
PreviousTime
variable.
SpawnTime
is the vari-
able that we use to spawn the damage report.
PreviousTime
will be set later; this
is used to mark the previous time we showed the damage report.
When the current time passed is greater than
SpawnTime
and
PreviousTime
to-
gether, we show the damage report. We first set the text of
TextMesh
to the value
of the damage variable. Then, we set its alpha value to one; this is so that the player
can see it on the screen.
Afterwards, we check whether
HasChanged
is false. If it is false, then we subtract
the health with our
Damage
variable. We then run the
ChangeBar
function. Time to
look at the next timer:
if(Time.time > (KillTime + PreviousTime))
{
DamageReport.text = "";
txtColor.a = 0;
PreviousTime = Time.time;
HasChanged = false;
}
The
if
statement is similar to the previous timer, but we check with
KillTime
in-
stead of
SpawnTime
.
KillTime
is what we'll use to hide the damage report. Within
the
if
statement in the first line, we set the text of
TextMesh
to an empty value. For
good measure, we set the alpha value of
TextMesh
to zero to hide it.
After this, we set the
PreviousTime
variable to the current time passed in-game.
This will represent the last time damage report in the game. Finally, we set the
HasChanged
variable to false.