Needing help with shooting script

I am wanting to make a shooting script like binding of isacc. So if i face right pressing D on my computer and i hold down my mouse button it shoots in that direction. I also need help with destroying the bullet clone. I still want to control delay and speed.

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

public class playerShoot : MonoBehaviour
{
[SerializeField] private float fireDelay;
private float lastTime;
public float bulletSpeed;
public GameObject projectilePrefab;

void Update()
{
if (Input.GetMouseButton(0))
{
Shoot();
}

}

void Shoot()
{
if (Time.time > lastTime + fireDelay)
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3 dir = mousePos - transform.position;
dir.Normalize();
GameObject projectile = Instantiate(projectilePrefab, transform.position, Quaternion.identity);
projectile.GetComponent().velocity = dir * bulletSpeed;
lastTime = Time.time;

}

}

}

Start with this so people can read your code.

The Feedback thread tag is for making suggestions to Unity directly.

Where in your code are you checking for holding down D? Destroying the bullet clone would probably be best implemented in a script attached to the bullet itself. Have it destroy itself OnCollisionEnter2D or after a time delay. I’m not clear what delay and speed you are referring to.