-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDamageScreenEffect.cs
More file actions
31 lines (27 loc) · 867 Bytes
/
Copy pathDamageScreenEffect.cs
File metadata and controls
31 lines (27 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using UnityEngine;
using UnityEngine.UI;
public class DamageScreenEffect : MonoBehaviour
{
public Image damageImage; // Assign the UI Image in the Inspector
public float fadeSpeed = 2f; // How fast the blood fades
private float alpha = 0f;
void Start()
{
// Ensure the image starts invisible
damageImage.color = new Color(1, 0, 0, 0);
}
void Update()
{
if (alpha > 0)
{
alpha -= Time.deltaTime * fadeSpeed; // Gradually fade out
alpha = Mathf.Clamp01(alpha); // Keep between 0 and 1
damageImage.color = new Color(1, 0, 0, alpha); // Update transparency
}
}
public void ShowDamageEffect()
{
alpha = 0.7f; // Make the screen turn red when hit
damageImage.color = new Color(1, 0, 0, alpha);
}
}