Files
Fishing2/Assets/UnityStandardAssets/Utility/TimedObjectActivator.cs
2025-05-10 12:49:47 +08:00

79 lines
1.4 KiB
C#

using System;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace UnityStandardAssets.Utility
{
public class TimedObjectActivator : MonoBehaviour
{
public enum Action
{
Activate = 0,
Deactivate = 1,
Destroy = 2,
ReloadLevel = 3,
Call = 4
}
[Serializable]
public class Entry
{
public GameObject target;
public Action action;
public float delay;
}
[Serializable]
public class Entries
{
public Entry[] entries;
}
public Entries entries = new Entries();
private void Awake()
{
Entry[] array = entries.entries;
foreach (Entry entry in array)
{
switch (entry.action)
{
case Action.Activate:
StartCoroutine(Activate(entry));
break;
case Action.Deactivate:
StartCoroutine(Deactivate(entry));
break;
case Action.Destroy:
Destroy(entry.target, entry.delay);
break;
case Action.ReloadLevel:
StartCoroutine(ReloadLevel(entry));
break;
}
}
}
private IEnumerator Activate(Entry entry)
{
yield return new WaitForSeconds(entry.delay);
entry.target.SetActive(value: true);
}
private IEnumerator Deactivate(Entry entry)
{
yield return new WaitForSeconds(entry.delay);
entry.target.SetActive(value: false);
}
private IEnumerator ReloadLevel(Entry entry)
{
yield return new WaitForSeconds(entry.delay);
SceneManager.LoadScene(SceneManager.GetSceneAt(0).name);
}
}
}