41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using System.Collections;
|
|
|
|
public class DamageDisplay : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI damageInfoText;
|
|
public float floatSpeed = 1.0f;
|
|
public float displayTime = 1.0f; // Adjust the duration you want the damage text to be displayed
|
|
public Vector3 initialPosition;
|
|
|
|
private void Start()
|
|
{
|
|
damageInfoText = GameObject.Find("UI").transform.GetChild(0).GetChild(9).gameObject.GetComponent<TextMeshProUGUI>();
|
|
initialPosition = damageInfoText.transform.position;
|
|
|
|
}
|
|
|
|
public IEnumerator ShowFloatDamageText(int damageAmount)
|
|
{
|
|
damageInfoText.text = $"Damage +{damageAmount}:\n Blood Hungry!!";
|
|
damageInfoText.gameObject.SetActive(true);
|
|
|
|
float elapsedTime = 0f;
|
|
|
|
while (elapsedTime < displayTime)
|
|
{
|
|
//the time.deltatime * 0.xf is very necessary to control the speed to which the text floats up, interesting because another text didnt require this
|
|
float translation = floatSpeed * Time.deltaTime * 0.3f;
|
|
damageInfoText.transform.Translate(Vector3.up * translation, Space.Self);
|
|
|
|
elapsedTime += Time.deltaTime;
|
|
|
|
yield return null;
|
|
}
|
|
|
|
damageInfoText.gameObject.SetActive(false);
|
|
damageInfoText.transform.position = initialPosition;
|
|
}
|
|
}
|