So I have a camera that moves forward by set increments every time my player leaves its viewport. It works fine, except if I get my player to stand just between one viewport and the new one, the camera flickers between the two scenes. Is there a way to fix this? I have a way to set scripted camera scenes too, and those don’t experience the same flickering because I set them manually, and I have a one-way barrier that doesnt allow the player to go back once they’ve entered a scripted scene.
using UnityEngine;
using System.Collections;
public class CameraScript : MonoBehaviour
{
private bool isScripted=false;
private int sceneNumber=0;
public Transform target;
void Update()
{
//this sets the left and right border to whatever the camera can see on the left and right sides
Vector3 rightBorder=camera.ViewportToWorldPoint (new Vector3(1,1,1));
Vector3 leftBorder=camera.ViewportToWorldPoint (new Vector3 (0,0,0));
//this makes it so that if the player hits the left or right border, the camera moves over to compensate.
if (target.transform.position.x >= rightBorder.x && isScripted==false)
{
transform.position=new Vector3 (rightBorder.x + 7f, transform.position.y, transform.position.z);
sceneNumber++;
}
if (target.transform.position.x <= leftBorder.x && isScripted==false)
{
transform.position=new Vector3 (leftBorder.x - 7f, transform.position.y, transform.position.z);
sceneNumber--;
}
if (sceneNumber==2)
{
isScripted=true;
transform.position=new Vector3 (34f, -6f, -10f);
camera.orthographicSize=10;
}
}
}