How would you add a random value to your transform.rotation?

So basically, my game is a platformer where the gun is aiming towards the mouse, kinda like Karlson 2D. I’m trying to do a shotgun spread, but what I have for the bullet spread so far is this -

` if (timeBtwShots <= 0)
{

        if (Input.GetMouseButton(0) && CurrentAmmo>0)
        {
            Instantiate(projectile, firePoint.position, Quaternion.Euler(0, 0, Random.Range(MinSpread, MaxSpread)));
            Instantiate(projectile, firePoint.position, Quaternion.Euler(0, 0, Random.Range(MinSpread, MaxSpread)));
            Instantiate(projectile, firePoint.position, Quaternion.Euler(0, 0, Random.Range(MinSpread, MaxSpread)));
            Instantiate(projectile, firePoint.position, Quaternion.Euler(0, 0, Random.Range(MinSpread, MaxSpread)));
            Instantiate(projectile, firePoint.position, Quaternion.Euler(0, 0, Random.Range(MinSpread, MaxSpread)));
            Instantiate(projectile, firePoint.position, Quaternion.Euler(0, 0, Random.Range(MinSpread, MaxSpread)));
            Instantiate(projectile, firePoint.position, Quaternion.Euler(0, 0, Random.Range(MinSpread, MaxSpread)));
            Instantiate(projectile, firePoint.position, Quaternion.Euler(0, 0, Random.Range(MinSpread, MaxSpread)));
            Instantiate(projectile, firePoint.position, Quaternion.Euler(0, 0, Random.Range(MinSpread, MaxSpread)));
            Instantiate(projectile, firePoint.position, Quaternion.Euler(0, 0, Random.Range(MinSpread, MaxSpread)));
            Instantiate(boomEffect, boomPoint.position, boomPoint.rotation);
            timeBtwShots = startTimeBtwShots;
            CurrentAmmo--;
        }
    }

Whenever I fire, the firing path is locked right. Even if the gun is pointed left or I’m facing left, the bullets fly left. What would be a way to fix this?

Also, is there a way to make the code less… messy? I have 10 instantiates, is there a way I can repeatedly instantiate?

`

Your projectiles have a script attached to them that’s making them move. That’s where you would fix the left-flying issue more than likely. I think giving them z-rotation won’t do anything - that would be a rotation around the forward-facing axis, so all of your pellets would still be forward-facing and won’t spread - I would instead rotate with even randomness about the X and Y axes. To instantiate multiple times you could use a for loop. Make sure in your setup that MaxSpread = Mathf.Abs(MinSpread) so that it could be evenly in any direction off of the straight path. Here’s everything in 1 try (untested):

pellets_per_shot = 10;

if (timeBtwShots <= 0) {

         if (Input.GetMouseButton(0) && CurrentAmmo>0)
         {
             for (int i = 0; i < pellets_per_shot; i++)
             {
                 Instantiate(projectile, firePoint.position, Quaternion.Euler(Random.Range(MinSpread/2, MaxSpread/2), Random.Range(MinSpread/2, MaxSpread/2), 0);
             }

             Instantiate(boomEffect, boomPoint.position, boomPoint.rotation);
             timeBtwShots = startTimeBtwShots;
             CurrentAmmo--;
         }
     }

If you post your projectile script I could expand my answer on how to get the correct direction after each pellet is instantiated.