wait for seconds in c#

I know that i need to use IEnumerator MyMethod() and make a coroutine in order to make a script wait for seconds and then do something, but i can’t do this inside my script =\

So, i have a OnCollision void and i wanted to use wait for seconds on it, like:

void OnCollisionEnter(Collision collision)
{
    Wait 2 seconds
    Do everything that i want
}

But i can’t. I am having multiple problems, such as “this thing shouldn’t be here”, “you can’t do this” and all. I have read the docs about this a lot of times but this just doesn’t work.

Here is my script:

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(AudioSource))]
public class EAimSys : MonoBehaviour //This is my Enemy script. As it doesn't have any mouse or keyboard, i need to use the WFS code.
{
    bool Click = false;
    bool target = false;

    public float fireRate = 0.5F;
    private float nextFire = 0.0F;
    public GameObject Flash;
    public Animator anim;




    void OnCollisionEnter(Collision collision)
    {
        {
            if (collision.gameObject.tag == "Player") //Here is where i want to start.

                //I wanted to use the wait for seconds code in here, so everything below this would need to wait x seconds before happening.
                //Why? Because otherwise my enemy would kill me instantly and i don't have enough experience to do anything more complicated than this.
                anim.SetTrigger("Shoot");
            AudioSource audio = GetComponent<AudioSource>();
            audio.Play();
            Flash.SetActive(true);
            Debug.Log("Player Hit!");
        }
    }

    void OnCollisionExit(Collision collision)
    {
        {
            if (collision.gameObject.tag == "Enemy")

            Flash.SetActive(false);
        }
    }
}

Well, my answer might be considered a little “dirty” but it is a possible solution.

You could delegate all that logic to other method which updates in the Update(). Having a float variable with the seconds you want to wait and reduce it using deltaTime (1 second = 1f).

use coroutines

    void OnCollisionEnter(Collision collision)
 {
StartCoroutine(Fire());
 }

Private Ienumerator Fire()
{
// do whatever you have to do to fire
yield return new WaitForSeconds(2);
StartCoroutine(Fire()); //if you put this here it will start the coroutine again over and over after 2 sec
}