Forum begins after the advertisement:
See discounted assets
:: Every time a floating text pops up, this error appears. I wonder if its because its trying to access ‘rect’ variable after destroying the floating text.
<code>IEnumerator GenerarTextoFlotanteCoroutine(string text, Transform target, float duration = 1f, float speed = 1f)
{
GameObject floatingText = new GameObject("Texto Flotante");
RectTransform rectTransform = floatingText.AddComponent<RectTransform>();
TextMeshProUGUI tmPro = floatingText.AddComponent<TextMeshProUGUI>();
tmPro.text = text;
tmPro.horizontalAlignment = HorizontalAlignmentOptions.Center;
tmPro.verticalAlignment = VerticalAlignmentOptions.Middle;
tmPro.fontSize = fontSize;
if (fontFamily) tmPro.font = fontFamily;
rectTransform.position = camaraReferencia.WorldToScreenPoint(target.position);
Destroy(floatingText, duration);
floatingText.transform.SetParent(instancia.damageTextCanvas.transform);
WaitForEndOfFrame wait = new WaitForEndOfFrame();
float time = 0;
float yOffset = 0;
while (time < duration)
{
yield return wait;
time += Time.deltaTime;
tmPro.color = new Color(tmPro.color.r, tmPro.color.g, tmPro.color.b, 1 - time / duration);
yOffset += Time.deltaTime * speed;
rectTransform.position = camaraReferencia.WorldToScreenPoint(target.position + new Vector3(0, yOffset));
}
}</code>
:: Also noticed that when the level up screen or results screen shows up, the text keeps over those.
EDIT: I found the solution if anyone else is experiencing this issue:
After setting the parent I added this line:
floatingText.transform.SetAsFirstSibling();
:: Thanks for posting the solution here Alejandro. Sorry for missing your post!
Advertisement below: