Loop just executes once
This loop just executes once, but the value from cutoff start with 1. So it should go through the loop until it reaches zero
do
{
cutoff -= 0.1f;
camera.GetComponent<SimpleBlit>().TransitionMaterial.SetFloat("_Cutoff", cutoff);
yield return 0;
} while (camera.GetComponent<SimpleBlit>().TransitionMaterial.GetFloat("_Cutoff") > 0f);
yield return 0;
How do you know only one iteration is executed?
I would advise you to cache the material to avoid the multiple calls to GetComponent
$$anonymous$$aterial transition$$anonymous$$aterial = camera.GetComponent<SimpleBlit>().Transition$$anonymous$$aterial;
do
{
cutoff -= 0.1f;
transition$$anonymous$$aterial.SetFloat("_Cutoff", cutoff);
Debug.Log("Cutoff: " + transition$$anonymous$$aterial.GetFloat("_Cutoff") ) ;
yield return 0;
} while (transition$$anonymous$$aterial.GetFloat("_Cutoff") > 0f);
yield return 0;
@Hellium I added a Debug.Log("Test"), and Test got only displayed once inside the console. This is how the code looks now:
do
{
cutoff -= 0.1f;
material.SetFloat("_Cutoff", cutoff);
Debug.Log("Test");
yield return null;
} while (material.GetFloat("_Cutoff") > 0f);
yield return 0;
I had intentionally put a Debug.Log("Cutoff: " + transition$$anonymous$$aterial.GetFloat("_Cutoff") ) ;
to print the value of the cutoff in the console and make sure the variable has a value of 1 when the loop starts.
Other question, are you sure the object holding the script is not disabled / destroyed when the coroutine runs?
Your answer
Follow this Question
Related Questions
How to change a variable used in a loop for the outside ? 1 Answer
Looped Animation 0 Answers
How do I loop music in C# 1 Answer