Make code less laggy? and one object in trigger rather than all?

So, i have this code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class cannonshoot : MonoBehaviour
{

    public float time;
    //public float damage;
    float timer;
    void Start()
    {
        time++;
        timer = time;
    }

    private void OnTriggerStay(Collider other)
    {
        if (timer <= 0.4)
        {
            if (other.gameObject.tag == "enemie")
            {
                other.gameObject.GetComponent<Health>().Min();
            }
            Debug.Log("Damage");
        }
    }

    void Update()
    {
        timer -= Time.deltaTime;
        if (timer < 0)
        {
            timer = time;
        }
        Debug.Log(timer);
    }
}

But, it’s EXTREMELY laggy, and gets all objects with tag “enemie” rather than just a few (i didn’t know how to make that work)

If you can help me, it’s greatly appriciated. :3

As @JVene says, you need to explain what you want the code to do better. But I’m guessing that the Cannon is instantiated as soon as it is fired and what you are trying to do is check if the timer has been longer than 0.6 seconds and the cannon collides with an enermie then execute the min function on the health script of the enermie. I think the reason for your problems is that you are using OnTriggerStay which is executed every frame that a trigger collider enters the canon. Try changing it to OnTrigerEnter and that will only be called once when the canon hits the enermie. In future though, you need to explain the problem in more detail as it isn’t that clear what you are trying to achieve.

Try removing Debug.Log(timer); and Debug.Log(“Damage”);
Writing to log possibly several times each and every frame would be quite laggy.
If you need to observe the values you can make the variable public and look at it in the editor.