Sakib Ahsan 442818b370 asd
2025-06-03 22:39:49 +02:00

30 lines
848 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
public class DestroyObject : MonoBehaviour
{
[Header("Destroy Settings")]
[Tooltip("Seconds to wait before destroying this GameObject automatically. \nSet to 0 or negative to disable autodestroy.")]
public float delaySeconds = 5f;
// Public flag to let your teammate disable the automatic timer if needed
public bool autoDestroyEnabled = true;
void Start()
{
// If autoDestroyEnabled is true and delaySeconds > 0, schedule the destruction
if (autoDestroyEnabled && delaySeconds > 0f)
{
Destroy(gameObject, delaySeconds);
}
}
/// <summary>
/// Public method that immediately destroys this GameObject.
/// GameManager can call this at any time.
/// </summary>
public void DestroySelf()
{
Destroy(gameObject);
}
}