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

public class BookFlying : MonoBehaviour
{
    
    public float flyingSpeed = -0.1f, levelDifficulty = 1f;
    public int level = 0;
    // Start is called before the first frame update
    void Start()
    {
        if (level == 0) levelDifficulty = 1f;
        else if (level == 1) levelDifficulty = 0.9f;
        else if (level == 2) levelDifficulty = 0.8f;
        else if (level == 3) levelDifficulty = 0.7f;
        else if (level == 4) levelDifficulty = 0.6f;
        else if (level == 1) levelDifficulty = 0.5f;
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.right * flyingSpeed *levelDifficulty* Time.deltaTime);
    }

    public void OnTriggerEnter2D(Collider2D collider){
        if (collider.CompareTag("censorWin")){
            GameObject.Find("Wizard").GetComponent<WizardMovement>().moveSpeed = 5f;
            flyingSpeed = 5f;
            StartCoroutine(LevelNext());
                  
        }
        if (collider.CompareTag("censorendgame")){
            GameObject.Find("Wizard").GetComponent<WizardMovement>().moveSpeed = 1.5f;
            flyingSpeed = -1.5f;
            
        }
    }

    IEnumerator LevelNext(){
        yield return new WaitForSeconds(1);
        GameObject.Find("LevelLoader").GetComponent<LevelLoader>().NextLevel();  

    }
}
