using System;
using ObjectsPool;
using UnityEngine;

public class Bullet : PoolObject
{
    [SerializeField] private Collider2D _collider;
    [SerializeField] private Rigidbody2D _rb;
    [SerializeField] private float speed = 15.0f;
    [SerializeField] private AudioClip hitSound;
    
    private Camera _cameraMain;

    private void Awake()
    {
        _cameraMain = Camera.main;
    }


    void FixedUpdate()
    {
        _rb.velocity = transform.right * speed;
    }

    private void OnTriggerEnter2D(Collider2D col)
    {
        if(col.CompareTag("Player")) return;

        if (col.CompareTag("BulletTarget") || col.CompareTag("Enemy") || col.CompareTag("TakeDamage"))
        {
            PlayerController.ShowCircleParticle?.Invoke(transform.position);
            SoundManager.PlaySFX?.Invoke(hitSound);
            if (col.CompareTag("TakeDamage"))
            {
                //Todo take damage
            }
        }
        
        Pool.Return(this);
    }
}
