I have a camera, that follows the player. Both of them are set to not get destroyed on scene change.
In each scene, I also have objects that’s transform sets the limit of the camera’s movement.
However, when changing the scene, the camera loses it’s reference to the old objects, but doesn’t replace it with the ones in the active scene. How would I make it relook the object references on scene load?
public class CameraLimits : MonoBehaviour
{
[SerializeField]
GameObject limitL;
[SerializeField]
GameObject limitR;
[SerializeField]
GameObject limitB;
void Update()
{
transform.position = new Vector3(Mathf.Clamp
(transform.position.x, limitL.transform.position.x, limitR.transform.position.x),
Mathf.Clamp(transform.position.y, limitB.transform.position.y, 100), transform.position.z);
}
}