- Home /
WaitForSeconds Not Working [SOLVED]
I actually don't know why this script isn't working. I got help & fixed it up. But once the WaitForSeconds code line comes into affect, nothing happens the script just stops. Here is the script. Any help would be nice.
P.S: There are no errors in the console!
P.S: Print("Work1"); & Print("Work2"); appear in the console.
Answer by hameed-ullah-jan · Feb 02, 2019 at 07:18 AM
your code looks fine, but if you want to destroy after some delay why dont you use Destroy(collision.gameObject, delay);
Answer by James_BadAlchemy · Feb 02, 2019 at 05:15 AM
What is your delay variable set to? I can't see where you set a value for it?
void OnCollisionEnter2D(Collision2D collision)
{
switch (collision.gameObject.tag)
{
case "EnemyDog":
StartCoroutine(DestroyLazerAfterDelay(collision, 0.25f)); //////////Here\\\\\\\\\\
print("Work1");
break;
case "Player":
break;
default:
break;
}
}
public IEnumerator DestroyLazerAfterDelay(Collision2D collision, float delay) //////////Here\\\\\\\\\\
{
print("Work2");
yield return new WaitForSeconds(delay);
print("Work3");
Destroy(collision.gameObject);
print("Work4");
}
0.25f
Your answer
Follow this Question
Related Questions
WaitForSeconds doesent run properly. 1 Answer
Ienumerate Wait for Seconds not working 1 Answer
Wait for seconds on collision 1 Answer
How to disable and re-enable components in the same function? 2 Answers
Wait until animation is finished 2 Answers