using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class BulletCollider : MonoBehaviour
{
    public int damage;
    public float lifespan;

    void OnCollisionEnter(Collision other)
    {
        Debug.Log("nf");
        if (other.transform.tag == "Player")
        {
            GameManager.instance.damagePlayer(damage);
        }
        else if(other.transform.tag=="enemy")
        {
            other.transform.GetComponent<EnemyAi>().health-=damage;
            if(other.transform.GetComponent<EnemyAi>().health<=0)
        {
            Destroy(other.gameObject);
        }
        }
    }
    void Update()
    {
        lifespan-=Time.deltaTime;
        if(lifespan<=0)
        {
            killBullet();
        }
    }
    public void killBullet()
    {
        Destroy(gameObject);
    }
}
