I am new to Unity and C# coding. Here’s my problem - i have fade out script and i use StartCoroutine and IEnumerator function to fade out an object but i want to fade out two object instantly. i tried some coding and i don’t know why is it not working even though it work on first object but second object do not fade out:
private IEnumerator CheckMatch()
{
if(_firstRevealed.id == _secondRevealed.id)
{
_score++;
scoreLabel.text = "Score: " + _score;
rend = _firstRevealed.GetComponent<SpriteRenderer>();
rend1 = _secondRevealed.GetComponent<SpriteRenderer>();
startFading();
if (_score == 6)
{
SceneManager.LoadScene("Menu");
}
}
else
{
yield return new WaitForSeconds(0.5f);
_firstRevealed.Unreveal();
_secondRevealed.Unreveal();
}
_firstRevealed = null;
_secondRevealed = null;
}
IEnumerator FadeOut1()
{
for (float f = 1f; f >= -0.05f; f -= 0.05f)
{
Color c = rend.material.color;
Color c1 = rend1.material.color;
c.a = f;
c1.a = f;
rend.material.color = c;
rend.material.color = c1;
yield return new WaitForSeconds(0.05f);
}
}
public void startFading()
{
StartCoroutine("FadeOut1");
}