How can i set gameobject to inactive аfter delay on CollisionEnter
Hi, here is code
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.name == "Enemy")
{
heroAnimator.SetBool("Dead", true);
hero.active = false;
}
}
How can i add delay before active = false?
Comment
Answer by Ali-hatem · Mar 19, 2016 at 05:07 PM
private float delaytime = 3f;
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.name == "Enemy")
{
heroAnimator.SetBool("Dead", true);
StartCoroutine (delayactiv());
}
}
IEnumerator delayactiv()
{
yield return new WaitForSeconds (delaytime);
hero.active = false;
}