How can I clamp my camera when my player meet the boss ? 2D platform

Hi!

I’m beginner in programming, and I’m making a 2D game platform (like super mario) and I want to clamp my camera when my player meet the boss at the end of my game. After beating the boss, I want to free the camera and go open the castle door as a last thing to do in this game level. I have a camera follow script, and I try to handle this problem by making a empty gameobject as “BossZone” with a box collider as detection way. I put this gameobject as a child of my main camera. I don’t know if this logic (box collider) is the correct one? Please help.

Here is my CameraFollow Script :

using UnityEngine;
public class CameraFollow : MonoBehaviour
{

public GameObject player;
public Vector3 velocity = Vector3.zero;
public float smoothTime = .15f;

public bool enableMinX = false;
public float minX = 0;
public bool enableMaxX = false;
public float maxX = 0;

public bool enableMinY = false;
public float minY = 0;
public bool enableMaxY = false;
public float maxY = 0;

public bool entreBossZone;

private Vector3 offset;

void Start()
{
offset = transform.position - player.transform.position;
}

void FixedUpdate()
{
var targetPosition = player.transform.position + offset;

var targetMinY = enableMinY ? minY : targetPosition.y;
var targetMaxY = enableMaxY ? maxY : targetPosition.y;
targetPosition.y = Mathf.Clamp(targetPosition.y, targetMinY, targetMaxY);

var targetMinX = enableMinX ? minX : targetPosition.x;
var targetMaxX = enableMaxX ? maxX : targetPosition.x;
targetPosition.x = Mathf.Clamp(targetPosition.x, targetMinX, targetMaxX);

transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);

}

}

5661292--589396--upload_2020-4-2_15-7-7.png

The value of Min X, Y and Max X, Y are the bounds of my camera from the start of the game to the end (bounds of my gamemap).

hi !
i want to do the same with my game, Did you found the solution of that problem? an can yous hare with me ?