first commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OTGIntegrated.Combat
|
||||
{
|
||||
public sealed class FloatingDamage : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float lifetime = 1.1f;
|
||||
[SerializeField] private float riseSpeed = 1.35f;
|
||||
|
||||
private TextMesh textMesh;
|
||||
private float age;
|
||||
|
||||
public static void Spawn(Vector3 position, int amount, Color color)
|
||||
{
|
||||
GameObject root = new GameObject("FloatingDamage");
|
||||
root.transform.position = position;
|
||||
FloatingDamage floatingDamage = root.AddComponent<FloatingDamage>();
|
||||
floatingDamage.Configure(amount.ToString(), color);
|
||||
}
|
||||
|
||||
private void Configure(string text, Color color)
|
||||
{
|
||||
textMesh = gameObject.AddComponent<TextMesh>();
|
||||
textMesh.text = text;
|
||||
textMesh.anchor = TextAnchor.MiddleCenter;
|
||||
textMesh.alignment = TextAlignment.Center;
|
||||
textMesh.characterSize = 0.22f;
|
||||
textMesh.fontSize = 48;
|
||||
textMesh.color = color;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
age += Time.deltaTime;
|
||||
transform.position += Vector3.up * riseSpeed * Time.deltaTime;
|
||||
|
||||
if (Camera.main != null)
|
||||
{
|
||||
transform.rotation = Quaternion.LookRotation(transform.position - Camera.main.transform.position, Vector3.up);
|
||||
}
|
||||
|
||||
if (textMesh != null)
|
||||
{
|
||||
Color color = textMesh.color;
|
||||
color.a = Mathf.Clamp01(1f - age / lifetime);
|
||||
textMesh.color = color;
|
||||
}
|
||||
|
||||
if (age >= lifetime)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user