I wanted to use this type of text animation for level up event as well (instead of the particle effect). I did this by using the DamageTextSpawner and adding a UnityEvent in BaseStat for onLeveledUp. I just want the text “Level Up!” to appear above the player’s head so I dont need to pass in any value. This is my DamageTextSpawner class:
using UnityEngine;
namespace RPG.UI.DamageText
{
public class DamageTextSpawner : MonoBehaviour
{
[SerializeField] DamageText damageTextPrefab = null;
[SerializeField] GameObject levelUpTextPrefab = null;
// Called when TakeDamageEvent<float> is invoked in Health
public void SpawnDamageText(float damageAmount)
{
DamageText instance = Instantiate<DamageText>(damageTextPrefab, transform);
instance.SetValue(damageAmount);
}
public void SpawnLevelUpText()
{
Instantiate<GameObject>(levelUpTextPrefab, transform);
}
}
}
I was just wondering if there is a better way to approach this? Should I create a separate gameobject with a canvas for the level up text or can I use the same canvas that has the damage text and do some adjusting there? Any help much appreciated!