备份CatanBuilding瘦身独立工程
This commit is contained in:
70
Assets/Scripts/EventPinball/tips/FloatingText.cs
Normal file
70
Assets/Scripts/EventPinball/tips/FloatingText.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
namespace game
|
||||
{
|
||||
[RequireComponent(typeof(TextMeshPro))]
|
||||
public class FloatingText : MonoBehaviour
|
||||
{
|
||||
[Header("Type")]
|
||||
public EventPinballBonusType FloatingTextType;
|
||||
|
||||
[Header("Movement Settings")]
|
||||
public float moveSpeed = 1f;
|
||||
public float fadeDuration = 1f;
|
||||
|
||||
[Header("Renderer")]
|
||||
public int OrderInLayer = 3;
|
||||
|
||||
private TextMeshPro textMesh;
|
||||
private float currentAlpha = 1f;
|
||||
private float timer = 0f;
|
||||
private Vector3 moveDirection = Vector3.up;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
textMesh = GetComponent<TextMeshPro>();
|
||||
|
||||
var renderer = GetComponent<Renderer>();
|
||||
renderer.sortingOrder = OrderInLayer;
|
||||
}
|
||||
|
||||
public void Initialize(string text, Vector3 position)
|
||||
{
|
||||
transform.position = position;
|
||||
textMesh.text = text;
|
||||
|
||||
currentAlpha = 1f;
|
||||
timer = 0f;
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// 移动
|
||||
transform.position += moveDirection * moveSpeed * Time.deltaTime;
|
||||
|
||||
// 淡出
|
||||
timer += Time.deltaTime;
|
||||
if (timer >= fadeDuration)
|
||||
{
|
||||
if (FloatingTextType == EventPinballBonusType.TypeScore)
|
||||
{
|
||||
FloatingTextPool.Instance.ReturnToScorePool(this);
|
||||
}
|
||||
else if (FloatingTextType == EventPinballBonusType.TypeMultiple)
|
||||
{
|
||||
FloatingTextPool.Instance.ReturnToMultiplePool(this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
currentAlpha = Mathf.Lerp(1f, 0f, timer / fadeDuration);
|
||||
var color = textMesh.color;
|
||||
color.a = currentAlpha;
|
||||
textMesh.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user