Game Development Reference
In-Depth Information
public TextMesh DamageReport;
public float Damage = 5;
Color txtColor;
public float SpawnTime = 2;
public float KillTime = 3;
public float PreviousTime = 0;
bool HasChanged = false;
The
TextMesh
object is the actual 3D text object that we use to show the damage
report in-game. The
Damage
variable is what will be shown in the text of our
Tex-
tMesh
. We use a
Color
variable so that we can modify the alpha value of the
Tex-
tMesh
object; this will allow us to turn on/off the
TextMesh
object without having to
instantiate it.
The next three float variables are used when we create a timer. We use the timer to
pick when we want to show or hide the damage report. Lastly, the
bool
variable will
help us check if we've taken damage or not.
Our next step will be to add a couple lines to our
Start()
function:
txtColor = DamageReport.color;
txtColor.a = 0;
The
txtColor
variable is what we'll use to show or hide the damage report. First,
we set it to the color of
TextMesh
, and then we set its alpha value to zero. We set it
to zero so that the player can only see it when damage is done.
The new Update function
Our next step is to add our
Update()
function. We will actually change this function
a lot, so I'll show you the entire function and then go through it step by step:
void Update()
{
currentBarLength = currentHealth /
maximumHealth;