'How to translate c# Task to Unity coroutine (OnCollisionEnter2D)

help to translate this code in coroutine. Im making game in unity and need to creat coroutine for it. I try made it, but it doesnt works.


        private void OnCollisionEnter2D(Collision2D collision)
        {
            if (collision.gameObject.CompareTag("player") && collision.contacts[0].normal.y > 0.5f)
            {
                Instantiate(block, objectspawn.position, objectspawn.rotation);
                Destroy(this.gameObject);
                 _coin.Play();

            }

        }


Solution 1:[1]

if (collision.gameObject.CompareTag("player") && collision.contacts[0].normal.y > 0.5f)
            {
                StartCoroutine(CreateBlock());

            }

IEnumerator CreateBlock(){
yield return new WaitForSeconds(1f);
Instantiate(block, objectspawn.position, objectspawn.rotation);
                Destroy(this.gameObject);
                 _coin.Play();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Raining Cycles