Here is the script that I am using for the camera. Right now, I manually have to set the boundaries by positioning the camera where it looks like it's the limit of the border. There are a few problems though. If i change the aspect ratio of the viewport in Unity, the boundaries won't work as intended.
What I'm looking for is a way to - see the maximum boundaries set(like an empty game objectt idk) - see where the camera can move(in the inspector with Gizmos.DrawLine)
Basically i want a system that i can reuse for other scenes with different boundaries size and that adapts to the screen's size. Thanks in advance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowTarget : MonoBehaviour
{
public GameObject target;
public Vector3 offset;
public float cameraSpeed;
private Vector3 velocity = Vector3.zero;
private Vector3 targetPosition;
public float leftLimit;
public float rightLimit;
public float topLimit;
public float botLimit;
// Start is called before the first frame update
void Start()
{
targetPosition = target.transform.position - offset;
}
void FixedUpdate() {
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, cameraSpeed);
}
// Update is called once per frame
void Update()
{
float clampedX = Mathf.Clamp(transform.position.x, leftLimit, rightLimit);
float clampedY = Mathf.Clamp(transform.position.y, topLimit, botLimit);
targetPosition = target.transform.position - offset;
}
}