using UnityEngine;

namespace Nan.Scripts
{
    public class PlayerBullet : MonoBehaviour
    {
        [SerializeField] private AudioSource _audioSource;

        public Vector2 Velocity { get; set; }

        private void Start()
        {
            Destroy(gameObject, 1);
        }

        private void Update()
        {
            GetComponent<Rigidbody2D>().velocity = Velocity ;
            transform.rotation = Quaternion.AngleAxis(Mathf.Atan2(-Velocity.x, Velocity.y) * Mathf.Rad2Deg, Vector3.forward);
        }

        private void OnCollisionEnter2D(Collision2D other)
        {
            _audioSource.Play();
            _audioSource.transform.SetParent(null);
            ScoreManager.Instance.AddScore(10, transform.position);
            Destroy(_audioSource.gameObject, 1.0f);
            Destroy(gameObject);
        }
    }
}