Bullet

PHOTO EMBED

Tue May 17 2022 18:35:30 GMT+0000 (Coordinated Universal Time)

Saved by @BiscuitTinx #c#

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

public class Bullet : MonoBehaviour
{

    public float speed = 20f;
    public int damage = 40;
    public Rigidbody2D rb;
    
    // Start is called before the first frame update
    void Start()
    {
        rb.velocity = transform.right * speed;
        Destroy(gameObject, 1);
    }

    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        Enemy enemy = hitInfo.GetComponent<Enemy>();
        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }
        
        if (hitInfo.gameObject.tag != "Enemy")
        {
            return;
        }

        Destroy(gameObject);
    } 
}
content_copyCOPY