using UnityEngine;

public class ShotAway : MonoBehaviour {
    [SerializeField] private float ShotSpeed = 15f;
    Vector3 direction;
    GameController gameController;

    void Start() {
        gameController = FindFirstObjectByType<GameController>();
    }
    public void SetDirection(Vector3 dir) {
        direction = dir.normalized;

        // Beräkna vinkel i grader
        float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

        // Sätt rotation på projektilen
        transform.rotation = Quaternion.Euler(0, 0, angle);
    }
    
    void Update() {
        transform.position += direction * ShotSpeed * Time.deltaTime;
    }

    void OnTriggerEnter2D(Collider2D collision) {
        if (collision.CompareTag("Enemy")) {
            Destroy(collision.gameObject); // Ta bort fienden
            Destroy(gameObject);           // Ta bort projektilen
            gameController.KilledAnemy();
        }
    }
}