1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2024-11-22 08:24:17 +00:00
gravity-fusion/Assets/Components/MessageBox.cs

47 lines
1.1 KiB
C#
Raw Permalink Normal View History

2019-10-07 20:02:46 +00:00
using System;
using UnityEngine;
using UnityEngine.UI;
public class MessageBox : MonoBehaviour {
public float disappearanceSpeed = 0.22f;
protected float opacity;
protected Image image;
protected Text text;
protected bool nextTriggered;
protected Action next;
// Start is called before the first frame update
protected void Awake()
{
text = GetComponent<Text>();
image = transform.parent.GetComponentInChildren<Image>();
}
public void Write(string message, Action next) {
text.text = message;
this.next = next;
nextTriggered = false;
opacity = 1f;
}
protected void Update()
{
if(opacity > 0f) {
opacity -= disappearanceSpeed * Time.deltaTime;
}
else {
if(!nextTriggered)
{
nextTriggered = true;
if(next != null) {
next();
}
}
}
text.color = new Color(text.color.r, text.color.g, text.color.b, opacity);
image.color = new Color(text.color.r, text.color.g, text.color.b, opacity);
}
}