using UnityEngine;

public class RotateSkybox : MonoBehaviour {

    /// <summary>
    /// Plus il y a de fps, plus l'animation est fluide
    /// </summary>
    [SerializeField] private int fps = 60;

    /// <summary>
    /// Combien de temps, en secondes, prend une rotation complète de la Skybox ?
    /// </summary>
    [SerializeField] private float loopInSeconds = 720f;

    public static Material skyboxMat = null;

    private static float rot = 0f;

    void Start() {
        if (GetComponent<Skybox>() == null) {
            Debug.LogError("Error : There must be a Skybox component on this GameObject !");
            return;
        } else {
            skyboxMat = GetComponent<Skybox>().material;
            InvokeRepeating("Rotate", 0, 1f / fps);
        }
    }

    void Rotate() {
        rot += 360 / (fps * loopInSeconds);
        skyboxMat.SetFloat("_Rotation", rot);
    }
}