Untitled

 avatar
unknown
plain_text
7 days ago
1.2 kB
3
Indexable
public class TimeStopSimple : MonoBehaviour
{
    public float duration = 3f;
    public float cooldown = 10f;
    public float range = 5f;

    private float timer = 0f;
    private bool isActive = false;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E) && timer <= 0)
        {
            Activate();
        }

        if (isActive)
        {
            duration -= Time.unscaledDeltaTime;
            if (duration <= 0)
            {
                Deactivate();
            }
        }

        if (timer > 0)
        {
            timer -= Time.unscaledDeltaTime;
        }
    }

    void Activate()
    {
        isActive = true;
        Time.timeScale = 0;
        KillEnemies();
        duration = 3f;
        timer = cooldown;
    }

    void Deactivate()
    {
        isActive = false;
        Time.timeScale = 1;
    }

    void KillEnemies()
    {
        Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, range);
        foreach (Collider2D hit in hits)
        {
            if (hit.CompareTag("Enemy")) // Assumes enemies have "Enemy" tag
            {
                Destroy(hit.gameObject);
            }
        }
    }
}
Editor is loading...
Leave a Comment