using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveCamUp : MonoBehaviour
{
    public GameObject bug;
    public GameObject bie;
    public GameObject mos;
    public float speed = 2;
    private MosQuito mosQuito;
    private Bug bug_scrp;
    //private Shrinking shrink;
    [SerializeField]//jeg bruker SerializeField for å kunne få tak i disse i scenen, men likevel beholde de som private, altså ikke endrer verdien i scriptet. Lett å endre i andre leveler derfor jeg har brukt dette
    private float xMax; //sier hvor mye x koordinaten til høyre
    [SerializeField]
    private float yMax; //samme som i x, bare y koordinater
    [SerializeField]
    private float xMin; //sier hvor lite x koordinatene kan være
    [SerializeField]
    private float yMin; //samme som x, bare med y
    [SerializeField]
    public Transform target;
    // Use this for initialization
    void Start()
    {
        target = mos.transform;
        // shrink = FindObjectOfType<Shrinking>();
        mosQuito = FindObjectOfType<MosQuito>();
        bug_scrp = FindObjectOfType<Bug>();
    }

    // Update is called once per frame
    void Update()
    {
        if (bug_scrp.canmovemos)
        {
            target = mos.transform;
        }
        if (mosQuito.canmovebug)
            target = bug.transform;
        //Three cameras. Each for each insect. Turn on when that insect is on and off to the insect we don't have anymore
        //Doesn't work because shrink is on every bubble 
        // if (shrink.canmovemos)
        //     target = mos.transform;
        // if (shrink.canmovebug)
        //     target = bug.transform;
        // if (shrink.canmovebie)
        //     target = bie.transform;
    }
    private void LateUpdate()
    {
        //Should start following player unless you are on the top pf the screen
      //  if (!shrink.stopmov)
            transform.position = new Vector3(Mathf.Clamp(target.position.x, xMin, xMax), Mathf.Clamp(target.position.y, yMin, yMax), transform.position.z);
        //transform.position = new Vector3(target.position.x, target.position.y, transform.position.z);
    }
}
