MiniGames/Assets/Scripts/CubeClash/CubeClash_ShockZone.cs

47 lines
1019 B
C#

using UnityEngine;
public class CubeClash_ShockZone : MonoBehaviour
{
[Header("Timing")]
public float chargeTime = 2f;
public float activeTime = 2f;
[Header("Lifetime")]
[Tooltip("Destroy this ShockZone after this many seconds from spawn.")]
public float autoDestroyAfter = 5f; // default 5s
private float timer;
private bool active = false;
void Start()
{
// Auto-destroy the whole object after N seconds
if (autoDestroyAfter > 0f)
Destroy(gameObject, autoDestroyAfter);
}
void Update()
{
timer += Time.deltaTime;
if (!active && timer >= chargeTime)
{
active = true;
timer = 0f;
}
else if (active && timer >= activeTime)
{
active = false;
timer = 0f;
}
}
private void OnTriggerStay(Collider other)
{
if (active && other.CompareTag("Zibu"))
{
Destroy(other.gameObject);
}
}
}