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

public class Bullet : MonoBehaviour
{
    public Rigidbody rb;
    public float dam;
    public float speed;
    Transform target;
    void Update()
    {
        if (target == null)
        {
            Destroy(gameObject);
            return;
        }
        transform.Translate(Vector3.forward * speed * Time.deltaTime);
        transform.LookAt(target.position);
    }
    public void SetTarget(Transform tar)
    {
        target = tar;
    }
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "mon")
        {
            Destroy(gameObject);
            target.GetComponent<Mon>().GetDam(dam);
        }
    }
}
