Temporarily disable blayer movement?

Hello,

In my game when the player hits a wall he shouldn’t be able to move for about 5 seconds. I got it to be disabled, howeveri can’t get it to go back to enabled. Here is my entire movement script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class movement : MonoBehaviour {

public Rigidbody2D player;
public float speed;
public float rotSpeed;
public GameObject wall;
public float delay;

private bool movementEnabled = true;

// Use this for initialization
void Start () {
    player = GetComponent<Rigidbody2D>();
    wall = GetComponent<GameObject>();
}

IEnumerator timeDisabled ()
{
    yield return new WaitForSeconds(delay);
    movementEnabled = true;
}

void OnCollisionEnter2D(Collision2D wall)
{
    movementEnabled = false;
}

void RotateLeft()
{
    transform.Rotate(Vector3.forward * rotSpeed);
}

void RotateRight()
{
    transform.Rotate(Vector3.back * rotSpeed);
}

void move()
{
    if (Input.GetKey(KeyCode.W))
    {
        player.velocity = (transform.up * speed);
    }
    else
    {
        player.velocity = new Vector2(0, 0);
    }

    if (Input.GetKey(KeyCode.A))
    {
        RotateLeft();
    }
    if (Input.GetKey(KeyCode.D))
    {
        RotateRight();
    }
}

// Update is called once per frame
void Update () {
    if (movementEnabled == true)
    {
        move();
    }
    else
    {
        timeDisabled();
    }
    
}

}

If you can help i’ll gladly try anithing.

Thank you.

Sure OnCollisionEnter2D() is called?
Call timeDisabled() as a Coroutine (StartCoroutine(timeDisabled):wink: