67 lines
1.5 KiB
C#
67 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
/// <summary>
|
|
/// 打开窗帘/窗户
|
|
/// </summary>
|
|
public class Control_Curtain : MonoBehaviour
|
|
{
|
|
public static Control_Curtain Instance;
|
|
/// <summary>
|
|
/// 开/关窗帘
|
|
/// </summary>
|
|
public Button opencurtain;
|
|
/// <summary>
|
|
/// 点击的窗帘
|
|
/// </summary>
|
|
public Transform curtain;
|
|
|
|
public Toggle Open;
|
|
public Toggle Close;
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
void Start()
|
|
{
|
|
//opencurtain.onClick.AddListener(() =>
|
|
//{
|
|
// Opencurtains();
|
|
//});
|
|
}
|
|
private void Update()
|
|
{
|
|
//如果没在播放动画 则可以继续点击按钮
|
|
if (curtain != null && !curtain.GetComponent<Animation>().isPlaying)
|
|
{
|
|
Open.interactable = true;
|
|
Close.interactable = true;
|
|
}
|
|
}
|
|
public void Opencurtains(bool isopen)
|
|
{
|
|
Open.interactable = false;
|
|
Close.interactable = false;
|
|
Opencurtain(isopen);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开关窗帘
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
void Opencurtain(bool isopen)
|
|
{
|
|
if (curtain.GetComponent<SkinnedMeshRenderer>().GetBlendShapeWeight(0) == 0&& !isopen)
|
|
{
|
|
curtain.GetComponent<Animation>().Play("窗帘开");
|
|
}
|
|
else if (curtain.GetComponent<SkinnedMeshRenderer>().GetBlendShapeWeight(0) == 100&& isopen)
|
|
{
|
|
curtain.GetComponent<Animation>().Play("窗帘关");
|
|
}
|
|
}
|
|
|
|
}
|