Hey, so I have a coroutine for a project that basically just sets the fade of a vignette for a simple running script. However when run the character will start sprinting the vignette will increase and then when the script tries to run the same coroutine but setting it to 0 it doesnt work. So once the character starts sprinting the vignette increases and stays on the screen forever. Running out of stamina or releasing left shift doesn’t change this
private void Update()
{
MyInput();
Look();
}
private void MyInput()
{
x = Input.GetAxisRaw("Horizontal");
y = Input.GetAxisRaw("Vertical");
SprintManager();
}
private void SprintManager()
{
if ((Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W)) && !isFatigued && currentStamina > 0)
{
currentStamina -= Time.deltaTime * drainRate;
isSprinting = true;
StartCoroutine(VignetteFade(maxVignette));
}
if (Input.GetKeyUp(KeyCode.LeftShift) || currentStamina <= 0)
{
isSprinting = false;
StartCoroutine(VignetteFade(0));
}
if (currentStamina < 0)
{
currentStamina = 0;
isFatigued = true;
StartCoroutine(FatigueTimer(fatigueTime));
}
if ((!isSprinting && !isFatigued) && currentStamina <= maxStamina)
{
currentStamina += Time.deltaTime * rechargeRate;
}
}
and this is the VignetteFade coroutine
private IEnumerator VignetteFade(float vigAim)
{
float time = 0;
Vignette vignette = postProcessing.profile.GetSetting<Vignette>();
float vigStart = vignette.intensity.value;
while (vigStart < vigAim)
{
Debug.Log("Trying to set vignette from " + vigStart + " to " + vigAim);
time += Time.deltaTime;
vignette.intensity.value = Mathf.SmoothStep(vigStart, vigAim, vignetteSpeed * time);
yield return null;
}
}
I’m not very good with coroutines but any answers to this would help. I’ve tried running the VignetteFade(0) in update in an
if (!isSprinting)
but also keeps the vignette on the screen.
Thanks