- Home /
Question by
kyomazunki · Feb 02, 2019 at 12:38 AM ·
variablevariableswaitforsecondstransfertransferring
Transfering Variables Between Sections [SOLVED]
Do you know how I would us a variable (Collision2D collision) in the first function & put it in the WaitForSeconds Function? Any help would be nice.
Comment
Best Answer
Answer by sean244 · Feb 02, 2019 at 02:42 AM
Re-write your code to the following
void OnCollisionEnter2D(Collision2D collision)
{
switch (collision.gameObject.tag)
{
case "EnemyDog":
StartCoroutine(DestroyLazerAfterDelay(collision, 1f));
break;
case "Player":
break;
default:
break;
}
}
public IEnumerator DestroyLazerAfterDelay(Collision2D collision, float delay)
{
yield return new WaitForSeconds(delay);
Destroy(collision.gameObject);
}