How would I go about making randomised guns, borderlands-style?

I’m making an RPG/FPS and I want guns to have random attachment(s) and I want their stats to vary within a certain boundary for each weapon type. The gun would consist of a base and a mixture one or more of the following: a site/scope attachment, a torch or laser attachment, a silencer attachment or some other muzzle peripheral which adds elemental damage and an attribute which boosts the character’s attack, defense, reload xp ect.

I would create the weapon with all the optional items childed to it, and randomly activate/deactivate each item at Start - like this:

// drag the extras items to the appropriate fields:
var scope: GameObject;
var laser: GameObject;
var silencer: GameObject;

private var hasScope: boolean;
private var hasLaser: boolean;
private var hasSilencer: boolean;

function Start(){
  hasScope = Random.value < 0.20; // scope chance: 20%
  hasLaser = Random.value < 0.35; // laser chance: 35%
  hasSilencer = Random.value < 0.25; // silencer chance: 25%
  scope.SetActiveRecursively(hasScope);
  laser.SetActiveRecursively(hasScope);
  silencer.SetActiveRecursively(hasScope);
}

The hierarchy for such weapon should be something like this:

  Weapon // "naked" weapon (without any extras)
    Scope // scope model
    Laser // laser model
    Silencer // silencer model

You can use the variables hasScope, hasLaser etc. to enable the corresponding features in your script.

Well you’ll need a ton of media, which is models, textures, animations, and other resources for visuals.

Coding, which this portion of the Unity site is about, would be a bit more difficult but let’s look at just one random value: size of clip.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public int numberOfRounds;
    void Start() {
        numberOfRounds = Random.Range(1, 32);
    }
}

This particular instance assigns a random number, from 1 to 32, to the number of rounds. Using your logic for reloading and firing, you would refer to this number of ammunition and subtract from it as you fired.

Something hints that this may be your first game. If so, start smaller, don’t try to create Borderlands or the next World of Warcraft.