Question by
Salanyel · Apr 19, 2016 at 01:04 PM ·
coroutinechild-to-gameobjectfading
Fade child object with a coroutine
Hi, I've got a problem when trying to fade my child object in a coroutine.
Here is my code :
IEnumerator fadeOutCoroutine()
{
Debug.Log("Coroutine fade out");
if (m_parent == null)
{
setParent();
}
int target = (int)Mathf.Round(m_fadeDuration * Application.targetFrameRate);
Debug.Log("Target ; " + target);
for (float frame = 0; frame <= target; ++frame)
{
foreach (Image image in m_parent.GetComponentsInChildren<Image>())
{
if (objectTofade(image.gameObject.name))
{
image.color = new Color(image.color.r, image.color.g, image.color.b, 1 - (frame / target));
Debug.Log(image.gameObject.name + " : " + image.color.a, image.gameObject);
}
}
yield return new WaitForEndOfFrame();
}
objectToFade only say if I have to fade the current object.
The output of my debug.log is ok : the value is correct from 1 to 0, but my object is not fading.
Does anyone know what I've done wrong ?
Thx by advance,
Comment
CrossFadeAlpha function might be useful. Doc: http://docs.unity3d.com/460/Documentation/ScriptReference/UI.Graphic.CrossFadeAlpha.html
I'm going to test this. You probably solve this issue !