miepzerino
2025-04-01 c8b8bec7b3ea533e3b7b0b2db03cc51101deccd6
Assets/Scripts/PlayerFloatingText.cs
File was renamed from Assets/Scripts/HealthText.cs
@@ -4,7 +4,7 @@
using TMPro;
using UnityEngine;
public class HealthText : MonoBehaviour
public class PlayerFloatingText : MonoBehaviour
{
    // x = oscillation amount (0 = no oscillation), y = upwards speed
    public Vector3 moveSpeed = new Vector3(25f, 75, 0);
@@ -15,8 +15,9 @@
    // start fading after x seconds
    public float startToFade = 1f;
    private float timeElapsed = 0f;
    private float randomStartingPointX;
    private float randomStartingPointY;
    public bool randomStartingPoint = false;
    private float randomStartingPointX = 0f;
    private float randomStartingPointY = 0f;
    private Vector3 startingPosition;
    RectTransform textTransform;
@@ -28,8 +29,11 @@
        textMeshPro = GetComponent<TextMeshProUGUI>();
        startingPosition = textTransform.position;
        // add random starting position for text
        randomStartingPointX = UnityEngine.Random.value - 0.5f;
        randomStartingPointY = UnityEngine.Random.value * 15f;
        if (randomStartingPoint)
        {
            randomStartingPointX = UnityEngine.Random.value - 0.5f;
            randomStartingPointY = UnityEngine.Random.value * 15f;
        }
        textTransform.position = new Vector3(textTransform.position.x, textTransform.position.y + randomStartingPointY, textTransform.position.y);
    }