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

public class FireBallController : MonoBehaviour {

    public GameObject splash;
    
    public void FireAt(Vector3 target, float magnitude)
    {
        var force = target - transform.position;

        force.Normalize();
        force *= magnitude;

        GetComponent<Rigidbody2D>().AddForce(force);
        GetComponent<Animator>().SetTrigger("Fire");
    }

    void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.gameObject.CompareTag("Wave"))
        {
            GameObject newSplash = Instantiate(splash);
            newSplash.transform.position = transform.position;
            gameObject.SetActive(false);
            AudioManager.Instance.PlaySplash();
        }
    }
}
