So I know what my problem is, but after hours of trying to fix it I can’t think of a way to do it. So when I attack the enemy (or target), the GUI is drawn on the target saying the amount of damage. But if I change targets (by clicking on a different enemy) while the hitmarker is still being shown, it then shows on the new target, not the one that actually took the damage. How can I prevent this?
Here is my code:
public void showHitMarker() {
Vector3 v3pos = Vector3.zero;
if (target) {
v3pos = target.transform.position;
v3pos = Camera.main.WorldToScreenPoint(v3pos);
v3pos.y += 25;
v3pos.y = Screen.height - v3pos.y;
v3pos.x -= 25;
}
if (showDamage > 0) {
if (!target)
showDamage = 0;
GUI.Label(new Rect(v3pos.x, v3pos.y, 50, 50), damage.ToString(), hitMarker);
showDamage -= Time.deltaTime;
}
}
As you can see, when i switch to a new target it would make sense that it is drawn on the new one. I’ve tried storing the right target to draw it on in a variable but I can’t figure out how to do that properly…
Any ideas?
Thanks