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

public class WellLid : MonoBehaviour
{
    // Start is called before the first frame update
    public Camera cam;
    public List<Transform> wellLids;
    private bool wasUnderwater = false;
    private void Awake()
    {
        cam = Camera.main;
    }
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {

        bool isUnderwater = cam.transform.position.y < 0;

        if (isUnderwater != wasUnderwater)
        {
            if (isUnderwater)
            {
                // 从水面上进入水下
                foreach (Transform wellLid in wellLids)
                {
                    wellLid.GetComponent<Animator>().Play("Take 001");
                }
            }
            else
            {
                // 从水下出来
                foreach (Transform wellLid in wellLids)
                {
                    wellLid.GetComponent<Animator>().Play("Take 001 0");
                }
            }
        }
        wasUnderwater = isUnderwater;

    }
}
