1
Fork 0
slime-blood-and-pain/Assets/Scripts/MessageBar.cs

34 lines
736 B
C#
Raw Permalink Normal View History

2019-04-28 13:29:17 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MessageBar : MonoBehaviour
{
public float disappearanceSpeed = 0.3f;
private float opacity;
private Text text;
// Start is called before the first frame update
void Start()
{
text = GetComponent<Text>();
opacity = 0f;
}
2019-04-28 14:28:31 +00:00
public void Write(string message, Color color) {
text.color = color;
2019-04-28 13:29:17 +00:00
text.text = message;
opacity = 1f;
}
void Update()
{
if(opacity > 0f) {
opacity -= disappearanceSpeed * Time.deltaTime;
}
text.color = new Color(text.color.r, text.color.g, text.color.b, opacity);
}
}