I let a gameobject fade out like this: Code (csharp): for (t = 0.0; t < 1.0; t += Time.deltaTime) { Object.renderer.material.color.a = Mathf.Lerp(1, 0, t) } But when it is done, it is still a little bit visible (on my galaxy note). You still can see the contours a little. I think it has something to do with timing but I'm not sure. Can anybody tell me how to let it fade out complete?
I can suggest workaround - disable mesh renderer, to guarantee visibility of object: Code (csharp): Object.renderer.enabled = false; or: Code (csharp): Object.renderer.enabled = Object.renderer.material.color.a > 0.01F;
The reason of you issue is here "t += Time.deltaTime" - you increnent t variable by deltaTime value. So if t = 0.95 and deltaTime = 0.5, then next value of t will equals 1.45 and for cycle will not run - last value of t will be 0.95 - and object still a little bit visible. Alternate way is allow t to be greater then 1: Code (csharp): for (t = 0.0; t < 2.0; t += Time.deltaTime) { Object.renderer.material.color.a = Mathf.Lerp(1, 0, t) }
Thank you all for your quick reply. t greater than 1 was the solution. And I understand why, thanks Patico.