i need a little help with my blood splat screen here is what i have but it wont fade
Moved to the correct forum, please edit your code to use code tags instead of quotes and include more information
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class HitHUD : MonoBehaviour {
/// <summary>
/// The sprite that is going to be display
/// </summary>
[Header("Hit Effect")]
public Image hitScreen;
public float setAlpha=0;
public float lastAlpha =0;
public float minAlpha =0;
public float healRate = 1f;
public int curHealthPercent;
public int lastHealthPercent;
/// <summary>
/// Used to find out health
/// </summary>
UserHUD userHUD;
// Use this for initialization
void Start ()
{
userHUD = GetComponent<UserHUD>();
curHealthPercent = userHUD.myHealthPercent;
}
// Update is called once per frame
void Update ()
{
//curHealthPercent = userHUD.myHealthPercent;
float tempNum;
if (curHealthPercent == 100)
return;
if (curHealthPercent == 0)
return;
if (curHealthPercent == lastHealthPercent)
return;
if (curHealthPercent <= 20)
minAlpha = 175;
if (curHealthPercent <= 60)
minAlpha = 230;
if (curHealthPercent > 85)
minAlpha = 255;
tempNum = (curHealthPercent/100 ) * 255;
setAlpha = 255 - tempNum;
if (curHealthPercent > lastHealthPercent)
{
ImageAlphaChange(lastAlpha,setAlpha,Time.time *healRate );
}
else
{
ImageAlphaChange(setAlpha,minAlpha,Time.time*healRate);
}
lastAlpha = setAlpha;
lastHealthPercent = curHealthPercent;
}
void ImageAlphaChange(float alphaStart, float alphaEnd, float transTime)
{
Color myColor;
for (float t = 0.0f; t < 1.0f; t += Time.deltaTime / transTime)
{
myColor = new Color32 (191, 0,0, (byte)Mathf.Lerp(alphaStart,alphaEnd,t));
hitScreen.color = myColor;
}
}
}