Hello! I am working with damage numbers (and health pickups) to be shown on screen. I have the code working to show me the number with a juicy random instantiate and a delayed fade. So, I don’t need any help with the text mesh instantiation itself. What I want to know, is if I can call my “TakeDamage()” method, which contains my DamageNumber text mesh assignment every time the enemy takes any form of damage? The last sentence would logically be something like:
//Whenever curhp gets reduced, call TakeDamage();
here is some visual aiding code to help you understand what I’m looking for:
public float curhp;
public float hpLost;
void Update () {
//if curhp altered: call TakeDamage()
//the variable "hpLost" is assigned damage through other scripts,
//in case you were wondering
}
void TakeDamage() {
objectSpeed = 60f;
Vector2 randomDirection = Random.insideUnitCircle * objectSpeed;
GameObject dicks = Instantiate(textMeshObject,transform.position,Quaternion.identity) as GameObject;
TextMesh text = (TextMesh)dicks.GetComponent(typeof(TextMesh));
text.text = "-" + hpLost.ToString();
dicks.rigidbody2D.AddRelativeForce(randomDirection);
}