Top down camera lock

i have tried the solution in:

my clip camera to the target so far is:

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

public class CameraClip : MonoBehaviour
{
    [SerializeField]
    Transform target;
    float yoffset = 20;
    float xoffset = -10;
    float zoffset = -10;

    void LateUpdate()
    {
        transform.position = new Vector3(target.position.x + xoffset, target.position.y + yoffset, target.position.z + zoffset);
    }
}

However, even though i have a collider and this clip on a parent to the main camera…the parent still goes right through collisions…the solution at the bottom of that link did not work. what is i missing to stop the camera from going through walls?
I’ve uploaded a pic to show the problem

It is passing through because you are setting the position directly via transform.position which will move the gameobject to that position ignoring the collisions. In Standard Assets there is a script called ProtectCameraFromWallClip to prevent wall clipping of camera which you can use.

I have figured out a way to lock it myself:

    public float lockxmin;
    public float lockzmin;
    [SerializeField]
    float lockxmax;
    [SerializeField]
    float lockzmax;
    if (transform.position.x < lockxmin || transform.position.x > lockxmax)
            {
                var temp = transform.position;
                temp.x = Mathf.Clamp(temp.x, lockxmin, lockxmax);
                transform.position = temp;
            }
            if (transform.position.z < lockzmin || transform.position.z > lockzmax)
            {
                var temp = transform.position;
                temp.z = Mathf.Clamp(temp.z, lockzmin, lockzmax);
                transform.position = temp;
            }