JJBB/Assets/Project/Script/ChildDelayShowControl.cs
2024-08-23 15:49:34 +08:00

52 lines
1.3 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using Games.LogicObj;
public class ChildDelayShowControl : MonoBehaviour
{
[System.Serializable]
public struct ChildInfo
{
public GameObject obj;
public float delay;
}
public ChildInfo[] ChildGameObjs;
private void Awake()
{
if (ChildGameObjs == null)
return;
for(int i=0;i< ChildGameObjs.Length;i++)
{
if (ChildGameObjs[i].obj != null)
{
ChildGameObjs[i].obj.SetActive(false);
ChildGameObjs[i].delay = Time.time + ChildGameObjs[i].delay;
}
}
}
private void Update()
{
if (ChildGameObjs.Length <= 0)
return;
List<ChildInfo> Leaves = new List<ChildInfo>();
for (int i = 0; i < ChildGameObjs.Length; i++)
{
if (ChildGameObjs[i].obj != null)
{
if (Time.time > ChildGameObjs[i].delay)
{
ChildGameObjs[i].obj.SetActive(true);
}
else
Leaves.Add(ChildGameObjs[i]);
}
}
ChildGameObjs = Leaves.ToArray();
}
}