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