How to get bullets to hit crosshair

I am trying to get my bullets to shoot the crosshair and it does this instead (the continuous bullets are a feature in my game so I used it to help demonstrate where the bullets go actually go).

Here is the picture:

And here’s my code

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

public class PlayerWeapon : MonoBehaviour {

    public GameObject bulletPrefab;

    public Transform bulletSpawn;

    public float bulletSpeed = 30;

    public float lifeTime = 3;
    
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Fire();
        }

        if (Input.GetKey(KeyCode.Mouse1))
        {
            Fire();
        }
    }

    private void Fire()
    {
        GameObject bullet = Instantiate(bulletPrefab);

        Physics.IgnoreCollision(bullet.GetComponent<Collider>(), bulletSpawn.parent.GetComponent<Collider>());

        bullet.transform.position = bulletSpawn.position;

        Vector3 rotation = bullet.transform.rotation.eulerAngles;

        bullet.transform.rotation = Quaternion.Euler(rotation.x, transform.eulerAngles.y, rotation.z);

        bullet.GetComponent<Rigidbody>().AddForce(bulletSpawn.forward * bulletSpeed, ForceMode.Impulse);

        StartCoroutine(DestroyBullerAfterTime(bullet, lifeTime));
    }

    private IEnumerator DestroyBullerAfterTime(GameObject bullet, float delay) {
        yield return new WaitForSeconds(delay);

        Destroy(bullet);
        
    }
}

Please help

(I think this person can help)

@azerty0220pl

This code would work if your gun was facing the crosshair at all times. To do this, simply fire a raycast from the camera to the nearest wall, get the hit point, and rotate the gun to face that point. For example:

public Transform Gun;
public Transform cam;

void Update()
{
     RotateGun();
}

void RotateGun()
{
     if (Physics.Raycast(cam.position, cam.forward, out RaycastHit hitInfo))
     {
          Vector3 direction = hitInfo.point - Gun.position;
          Gun.rotation = Quaternion.LookRotation(direction);
     }
}

You don’t typically implement bullets as physics collider objects since any physics system has issues with high velocity. Basically the engine sees the bullet on one side, then at the next physics step on the far side, and there’s no frame with a collision. You can tweak rigidbody properties to continuous detection to ‘sweep’ ahead at each step and try to anticipate a collision, but typically for a fast projectile you raycast an instantaneous hit and create an illusion of a tracer as a visual effect, and/or delay or adjust the impact position for bullet drop etc.