check if object is colliding with another

Ok so ive tried OnCollisionStay as well as enter but none of theese apear to work . my camera is attached to the head of the player the players spine rotates with the mouselook using

transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y,-rotationZ);

the camera gets pushed into walls what can i do do stop this i wish to check if its colliding then freeze the mouselook if it is but since the two functions dont work what can i do?

Before applying the camera’s motion (i.e. give it input from the mouse, but don’t actually move with that input yet), fire a short raycast in the direction the camera will move. If it hits a wall (make sure it doesn’t just hit the player), then don’t apply the movement in the opposite direction of the wall’s normal. I specify that so movement can, therefore, still be applied perpendicular to the wall; it would make sense to be able to have motion along a wall rather than stopping entirely.

Use. OnTriggerEnter. Make the boxcollider or whatever collider you are using a little bit bigger than the wall itself. so your character can actually touch the collider.

When OnTriggerEnter(Collider other){GetComponent.< mouselook> ().enabled = false;}

EDIT : Instead of doing the method I said above, you can also just add an invisible collider infront the wall. Just so you can’t reach the wall.