CQ_Intelligent-Technology-T.../Assets/Scripts/Control_Curtain.cs

55 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class Control_Curtain : MonoBehaviour
{
public static Control_Curtain Instance;
/// <summary>
/// 开/关窗帘
/// </summary>
public Button opencurtain;
/// <summary>
/// 点击的窗帘
/// </summary>
public Transform curtain;
private void Awake()
{
Instance = this;
}
void Start()
{
opencurtain.onClick.AddListener(() =>
{
StartCoroutine(Opencurtain());
});
}
/// <summary>
/// 开关窗帘
/// </summary>
/// <returns></returns>
IEnumerator Opencurtain()
{
if (curtain.GetComponent<SkinnedMeshRenderer>().GetBlendShapeWeight(0) == 0)
{
opencurtain.GetComponentInChildren<TextMeshProUGUI>().text = "拉开窗帘";
for (int i = 1; i < 101; i++)
{
curtain.GetComponent<SkinnedMeshRenderer>().SetBlendShapeWeight(0, i);
yield return new WaitForSeconds(0.025f);
}
}
else if (curtain.GetComponent<SkinnedMeshRenderer>().GetBlendShapeWeight(0) == 100)
{
opencurtain.GetComponentInChildren<TextMeshProUGUI>().text = "拉起窗帘";
for (int i = 100; i >= 0; i--)
{
curtain.GetComponent<SkinnedMeshRenderer>().SetBlendShapeWeight(0, i);
yield return new WaitForSeconds(0.025f);
}
}
}
}