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

public class AnimCovid : MonoBehaviour
{
    public float xMax, yMax, xMin, yMin;
    public float xDir, yDir;
    public float xSpeed, ySpeed;

    public Vector3 scaleMax, scaleMin;
    public float scaleSpeed, scaleDir;

    public float rotation, rotationMax, rotationMin, rotationSpeed, rotationDir;
    
    // Start is called before the first frame update
    void Start()
    {
        xMax = transform.position.x + 0.25f;
        xMin = transform.position.x - 0.25f;
        yMax = transform.position.y + 0.25f;
        yMin = transform.position.y - 0.25f;

        xDir = 1;
        yDir = 1;

        xSpeed = 0.1f;
        ySpeed = 0.1f;

        scaleMax = new Vector3(1.1f,1.1f,0f);
        scaleMin = new Vector3(0.9f,0.9f,0f);
        scaleSpeed = 0.25f;
        scaleDir = 1;

        rotationMax = 165f;
        rotationMin = 15f;
        rotationSpeed = 5f;
        rotationDir = 1;
    }

    // Update is called once per frame
    void Update()
    {
        
        if (transform.position.x >= xMax && xDir == 1 || 
            transform.position.x <= xMin && xDir == -1)
        {xDir *= (-1);}

        if (transform.position.y >= yMax && yDir == 1 || 
            transform.position.y <= yMin && yDir == -1)
        {yDir *= (-1);}

        transform.localPosition += new Vector3(xSpeed * xDir * Time.deltaTime,ySpeed * yDir * Time.deltaTime,0f);

        if (transform.localScale.x >= scaleMax.x && scaleDir == 1 ||
            transform.localScale.x <= scaleMin.x && scaleDir == -1)
        {scaleDir *= (-1);}

        transform.localScale += new Vector3(scaleSpeed * scaleDir * Time.deltaTime,scaleSpeed * scaleDir * Time.deltaTime,0f);

        if (transform.eulerAngles.z >= rotationMax && rotationDir == 1 ||
            transform.eulerAngles.z <= rotationMin && rotationDir == -1)
        {
            rotationDir *= (-1);
        }
        //rotation += ;
        transform.Rotate(0f, 0f, rotationSpeed * rotationDir * Time.deltaTime);
    }
}
