Files
3d-guanwang/Assets/Scripts/WellLid.cs
XuGaoFeng c217787c5c add codes
2026-08-25 15:15:42 +08:00

49 lines
1.1 KiB
C#

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;
}
}