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

public class Needle : Bullet
{
    public float speed = 20;

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

    private void Update()
    {
        var stepLength = speed * Time.deltaTime;
        var direction = transform.forward;

        if (Physics.Raycast(transform.position, direction, out var hit, stepLength))
        {
            var bubble = hit.collider.attachedRigidbody?.GetComponent<Bubble>();
            if (bubble != null)
            {
                bubble.Burst();
            }
            Destroy(gameObject);
        }
        else
        {
            transform.position += direction * stepLength;
        }
    }
}
