using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    public Rigidbody2D rb;
    [System.NonSerialized]public int setDmg;
    private int Damage;
    [System.NonSerialized]public string OwnTag;
    private float wait;
    private void Start()
    {
        Damage = setDmg;
        rb.AddForce((Vector2)(Quaternion.Euler(0,0,rb.rotation) * Vector2.right) * 100, ForceMode2D.Impulse);
        wait = 10;
    }
    private void FixedUpdate()
    {
        wait -= Time.deltaTime;
        if(wait <= 0)
        {
            GameObject.Destroy(gameObject);
        }
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other.CompareTag(OwnTag))
        {
            return;
        }
        if(other.CompareTag("Bullet"))
        {
            return;
        }
        if(other.TryGetComponent<Health>(out Health health))
        {
            health.RemoveHP(Damage);
        }
        GameObject.Destroy(gameObject);
    }
}
