using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraBehavior : MonoBehaviour
{
public Transform Character;
public float ymin;
public float ymax;
public float size;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
size = Camera.main.orthographicSize; // finding the size of the screen
ymin = transform.position.y - (size-2); // finding the y min for camera follow
ymax = transform.position.y + (size-1); //finding the y max for the camera follow
if (!(Character.position.y < ymin) && !(Character.position.y > ymax))// checking if in bounds for normal camera behavior
{
transform.position = new Vector3(Character.position.x, transform.position.y, transform.position.z);
}
else// if its not...
{
if (Character.position.y < ymin)//if its going below
{
transform.position = new Vector3(Character.position.x, Character.position.y + (size-2), transform.position.x);
}
if (Character.position.y > ymax)
{
transform.position = new Vector3(Character.position.x, Character.position.y + (size-1), transform.position.x);
}
}
}
}