first commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace OTG.Lab06.Combat
|
||||
{
|
||||
public sealed class FloatingDamage : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Text label;
|
||||
[SerializeField] private float lifetime = 1.1f;
|
||||
[SerializeField] private float riseSpeed = 1.2f;
|
||||
|
||||
private float remaining;
|
||||
|
||||
public void Initialize(float amount)
|
||||
{
|
||||
if (label == null)
|
||||
{
|
||||
label = GetComponentInChildren<Text>();
|
||||
}
|
||||
|
||||
label.text = Mathf.RoundToInt(amount).ToString();
|
||||
remaining = lifetime;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
transform.position += Vector3.up * (riseSpeed * Time.deltaTime);
|
||||
if (Camera.main != null)
|
||||
{
|
||||
transform.rotation = Quaternion.LookRotation(transform.position - Camera.main.transform.position, Vector3.up);
|
||||
}
|
||||
|
||||
remaining -= Time.deltaTime;
|
||||
float alpha = Mathf.Clamp01(remaining / lifetime);
|
||||
if (label != null)
|
||||
{
|
||||
Color color = label.color;
|
||||
color.a = alpha;
|
||||
label.color = color;
|
||||
}
|
||||
|
||||
if (remaining <= 0f)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user