i want to wait 2 sec before destroying a gameObject, this is my code… i have no idea why its not working.
anyone can help me?
Code
using UnityEngine;
using System.Collections;
public class goomba_kill : MonoBehaviour
{
Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent ();
}
/*
void Update ()
{
}*/
void OnTriggerEnter2D (Collider2D coll)
{
if (coll.gameObject.tag == “Player”) {
anim.SetBool (“goomba_dead”, true);
audio.Play ();
StartCoroutine(MyMethod());
Destroy (this.gameObject);
}
}
IEnumerator MyMethod() {
Debug.Log(“Before Waiting 2 seconds”);
yield return new WaitForSeconds(2);
Debug.Log(“After Waiting 2 Seconds”);
}
}