Files
BABA_YAGA/Assets/Scripts/Trap/PoisonScreenOverlay.cs
2026-07-02 08:59:23 +07:00

48 lines
1.1 KiB
C#

using UnityEngine;
using UnityEngine.UI;
public class PoisonScreenOverlay : MonoBehaviour
{
[SerializeField] private Image overlayImage;
[SerializeField] private float fadeSpeed = 2f;
private float targetAlpha = 0f;
private float currentAlpha = 0f;
void Start()
{
if (overlayImage == null)
{
overlayImage = GetComponent<Image>();
}
if (overlayImage != null)
{
Color c = overlayImage.color;
c.a = 0f;
overlayImage.color = c;
overlayImage.enabled = false;
}
}
void Update()
{
if (overlayImage == null) return;
if (Mathf.Abs(currentAlpha - targetAlpha) > 0.01f)
{
currentAlpha = Mathf.MoveTowards(currentAlpha, targetAlpha, fadeSpeed * Time.deltaTime);
Color c = overlayImage.color;
c.a = currentAlpha;
overlayImage.color = c;
overlayImage.enabled = currentAlpha > 0.01f;
}
}
public void SetOverlayActive(bool active)
{
targetAlpha = active ? 0.6f : 0f; // maximum 60% opacity green overlay
}
}