I’m making a top-down rpg and have an orthographic camera. I made a script that controls different variables on the camera (mainly changing the target). When I was adding the zoom feature it didn’t work properly:
public GameObject NewTarget;
public CameraController Camera;
public Camera MainCam;
public GameObject Player;
public float CameraZoom;
public float CameraZoomDefault;
// Use this for initialization
void Start()
{
CameraZoomDefault = MainCam.orthographicSize;
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.name == "Player")
{
Camera.Target = NewTarget;
MainCam.orthographicSize = CameraZoom;
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.name == "Player")
{
Camera.Target = Player;
CameraZoom = CameraZoomDefault;
}
}
Everything except the zoom is working. I can make the camera zoom out when I enter the trigger but when I exit it doesn’t zoom back in. Thanks in advance!