38 lines
761 B
C#
38 lines
761 B
C#
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class PopupMessage : MonoBehaviour
|
||
|
{
|
||
|
public Text Content;
|
||
|
public float MessageTime;
|
||
|
|
||
|
public System.Action OnFinishedAction;
|
||
|
|
||
|
public PopupMessage Init(string message, float time = 2)
|
||
|
{
|
||
|
Content.text = message;
|
||
|
MessageTime = time;
|
||
|
gameObject.SetActive(true);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
if (MessageTime > 0)
|
||
|
{
|
||
|
MessageTime -= Time.deltaTime;
|
||
|
|
||
|
if (MessageTime <= 0)
|
||
|
{
|
||
|
OnFinishedAction?.Invoke();
|
||
|
Destroy(gameObject);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void OnClick()
|
||
|
{
|
||
|
Destroy(this.gameObject);
|
||
|
OnFinishedAction?.Invoke();
|
||
|
}
|
||
|
}
|