Problem with gravity, OnCollisionEnter and OnCollisionExit

Description: I want my gameObject to rotate by 90 degrees when it collides with wall. After that i want to turn off gravity so it can go upwards. When it gets off the wall i want to reset rotation and turn gravaty back on. Problem: When I use OnCollisionEnter it works (rotates gameObject and turns off gravity) but when I add OnCollisionExit (to reset rotation and turn gravity on when there is no more wall) gravity dosen’t turn off in OnCollisionEnter function it stays On always. Note that OnCollisionEnter works when OnCollisionExit isn’t added in script.

Here is my code

void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == “Colli”)
{

        Vector3 rotatY = new Vector3(-90, 0, 0);
        transform.Rotate(rotatY);
        rb.useGravity = false;
    }

}
void OnCollisionExit(Collision other)
{

    Vector3 resetRot = new Vector3(0, 0, 0);
    transform.Rotate(resetRot);
    rb.useGravity = true;

}

Thats because you are not testing if you exited the wall. Change OnCollisionExit() to this:

 void OnCollisionExit(Collision other)
 {
    if(other.gameObject.tag == "Colli")
    {
        Vector3 resetRot = new Vector3(0, 0, 0);
        transform.Rotate(resetRot);
        rb.useGravity = true;
    }
 }

//May this will work for you
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == “Colli”) {

     Vector3 rotatY = new Vector3(-90, 0, 0);
     transform.Rotate(rotatY);
     rb.useGravity = false;
 }

else
{
Vector3 resetRot = new Vector3(0, 0, 0);
transform.Rotate(resetRot);
rb.useGravity = true;
}

}