using UnityEngine;

public class Squeak : MonoBehaviour
{
    [Tooltip("assign to pivot child object of rat")]
    public GameObject pivot;
    [Tooltip("squeak bubble prefab")]
    public GameObject bubble;
    [Header("setting")]
    public float range = 10;
    public float cooldown = 5;
    float lastS;
    
    RottaMovement controller;
    GameObject activeBubble;

    
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        controller = gameObject.GetComponent<RottaMovement>();
    }
    public void spawnBubble(Vector3 targetPosition)
    {
        if(Time.time > lastS + cooldown)
        {
            lastS = Time.time;
            //direction = (targetPosition - transform.position).normalized;
            pivot.transform.LookAt(targetPosition);

            activeBubble = Instantiate(bubble, pivot.transform.position + (pivot.transform.forward * range), transform.rotation);
            activeBubble.GetComponent<bubble>().forceDirection = pivot.transform.forward;
            Debug.DrawLine(transform.position, transform.position + pivot.transform.forward * range, Color.red, 10);
            //Debug.Log(direction);
        }

    }
}
