Trouble lerping values during a coroutine, I’m able to do so within the update, where have I gone wrong?
IEnumerator colorSplashTog()
{
//Fade From Black
colorRef_A = Mathf.Lerp (colorRef_A, 0f, Time.smoothDeltaTime);
colorSplash.color = new Color (0, 0, 0, colorRef_A);
yield return new WaitForSeconds(3f);
}
I feel I’ve followed the same code structure as the example provided here:
As angrypenguin pointed out, you shouldn’t be using time delta directly if you’re looking for a linear interp:
IEnumerator colorSplashTog(float duration)
{
//Fade From Black
float t = 0;
Color fr = Color.Black;
Color to = Color.Clear;
while(t < 1) {
t += Time.smoothDeltaTime / duration;
colorSplash.color = Color.Lerp (fr, to, t);
yield return null;
}
}
As a bonus, you could also stick the fr and to parameters into the method signature itself, so it’s more reusable.
IEnumerator colorSplashTog(Color fr, Color to, float duration)
Thank you guys for the feedback, I am looking for a non-linear progression with this though. I’ve since taken the time to build a cut off point so it doesn’t continuously interpolate This has been helpful, as I didn’t fully understand this before and now have a much better grasp on it.
I am currently trying to slim the code down though,
The commented code seems to be working, although it doesn’t always rotate properly…Not sure why this is yet.
The uncommented code obviously doesn’t work because the vector3 isn’t able to be converted to a float…this makes sense to me but I’m wondering if there is another way to write the commented code in a shorter way? The game allows several different rotations controlled by buttons (EX: You click a button and it rotates to the position). If I were able to get the broken code working it would decrease this script by a significant amount…