Still walk when collide with object

I have this script so when i walk into the object with the tag stuck speed = 0.
I do this to prevent some bugs.
So when i walk into the object now, speed = 0. But then i can’t move left or right and im just stuck in the collider. I want it so i don’t get stuck and i freely can walk around when i collide with it, without getting stuck.
Here is the script that i made:

#pragma strict

var mSpeed : float  = 3;
var walk = false;
function Start () {

}

function Update () {

if(Input.GetButton("right"))
{
transform.position = transform.position + Vector3(mSpeed,0,0)     *     Time.deltaTime;
}

if(Input.GetButton("left"))
{
transform.position = transform.position + Vector3(-mSpeed,0,0)     *     Time.deltaTime;
}

}


function OnCollisionEnter2D(coll: Collision2D)
{

if(coll.gameObject.tag == "stuck")
{
mSpeed = 0;
}

}

Instead of `if(Input.GetButton(“”)){

} it should be if(Input.GetKey(“WhatEverKey”)){

//do things here

}`

simple mistake I do this all the time hope it helped

The problem is you shouldn’t have entered the collider. Now you are colliding you will always be colliding so forcing the speed to 0.

You really need to sort out why you needed to put mSpeed=0.

PS - I assume you are not using a character controller. That is one option as it sorts this stuff out for you.