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

public class ParallaxLayer : MonoBehaviour
{
    [Range(0, 1)]
    public float xMultiplier = 1;

    [Range(0, 1)]
    public float yMultiplier = 1;

    Vector3 startPosition;

    public bool sun;

    public bool moon;

    Vector3 offset = Vector2.zero;

    void Start()
    {
        startPosition = transform.position;
    }

    void Update()
    {
        if (sun) {
            int sec = DayLoopManager.Get().sec;

            sec -= 90;
            if (sec < 0) {
                sec = 0;
            }
          
            offset = new Vector3(0, sec * 3);
           
            Vector3 pos = startPosition;

            pos.x -= Camera.main.transform.position.x * -xMultiplier;
            pos.y -= Camera.main.transform.position.y * -yMultiplier;

            Vector3 p = transform.position;

            p.x = p.x * 0.95f + (pos.x + offset.x) * 0.05f;
            p.y = p.y * 0.95f + (pos.y + offset.y) * 0.05f;

            transform.position = p;

            //pos + offset

        } else if (moon) {
            int sec = DayLoopManager.Get().sec;

            sec -= 90;
            if (sec < 0) {
                sec = 0;
            }
          
            offset = new Vector3(0, -sec * 3);
           
            Vector3 pos = startPosition;

            pos.x -= Camera.main.transform.position.x * -xMultiplier;
            pos.y -= Camera.main.transform.position.y * -yMultiplier;

            Vector3 p = transform.position;

            p.x = p.x * 0.95f + (pos.x + offset.x) * 0.05f;
            p.y = p.y * 0.95f + (pos.y + offset.y) * 0.05f;

            transform.position = p;

        } else {
            Vector3 pos = startPosition;

            pos.x -= Camera.main.transform.position.x * -xMultiplier;
            pos.y -= Camera.main.transform.position.y * -yMultiplier;

            transform.position = pos;

        }
    }
}
