- Home /
How to fade out two gameObject instantly???,
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");
}
Answer by SectorCodec · Dec 26, 2018 at 08:46 AM
What I understand is that you want to instantly Vanish two objects. If that is the case then why use fading you can just disable the renderer or disable the game object by using gameObject.SetActive(false).
Ah, sorry. i don't mean instantly(sorry about my English). i want two object to fade out when choosing those. actually, i am making memory card game through tutorial but i want two card match to fade out from the scene.
Your answer
Follow this Question
Related Questions
NullReferenceException appears when fading a GUITexture 1 Answer
Fading Canvas Group 1 Answer
Fading off texture and multiple instances 0 Answers
fade-teleport not working 1 Answer
GUITexture fades in but not out. 1 Answer