78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
|
|
//use lean tween next time
|
|
|
|
namespace Lemon.GenericLib.VFX
|
|
{
|
|
public class Popup_Text : MonoBehaviour
|
|
{
|
|
TextMeshPro PopupText;
|
|
public string text;
|
|
public float lifetime = 2;
|
|
public float startSpeed;
|
|
public float speed;
|
|
private float targetSpeed;
|
|
private float size;
|
|
private float targetSize;
|
|
public Transform parent;
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
PopupText = GetComponent<TextMeshPro>();
|
|
PopupText.text = text;
|
|
targetSpeed = startSpeed;
|
|
size = 0;
|
|
targetSize = 1;
|
|
StartCoroutine(LifeTime());
|
|
parent = transform.parent;
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
|
|
transform.localPosition += Vector3.up * targetSpeed * Time.deltaTime;
|
|
transform.localScale = new Vector3(transform.localScale.x, size);
|
|
targetSpeed = Mathf.Lerp(targetSpeed, speed, 5 * Time.deltaTime);
|
|
size = Mathf.Lerp(size, targetSize, 20 * Time.deltaTime);
|
|
|
|
if (parent != null)
|
|
{
|
|
if (parent.localRotation.y != 0)
|
|
{
|
|
|
|
transform.localRotation = Quaternion.Euler(0, parent.rotation.y - 180, 0);
|
|
}
|
|
else
|
|
{
|
|
transform.localRotation = Quaternion.Euler(0, 0, 0);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void SetText(string text)
|
|
{
|
|
this.text = text;
|
|
PopupText.text = this.text;
|
|
}
|
|
|
|
IEnumerator LifeTime()
|
|
{
|
|
yield return new WaitForSeconds(lifetime);
|
|
targetSize = 0;
|
|
Destroy(gameObject, 0.25f);
|
|
}
|
|
|
|
}
|
|
}
|