ammo count help

I am currently using the first person shooter tutorial, and though i know its pretty out of date thats irrelevant to my problem. On the GUI it shows the current ammo count of my first weapon. Ive added in a heavy rifle right now, and the ammo for that is showing. However im trying to get it to change to my regular rifle when that is equipped. My current code isnt changing the two. The code I have is as follows:

private var machineGun : MachineGun;
private var rocketLauncher : RocketLauncher;
private var heavyMachineGun : HeavyMachineGun;

function Awake () {
machineGun = GetComponentInChildren(MachineGun);
rocketLauncher = GetComponentInChildren(RocketLauncher);
heavyMachineGun = GetComponentInChildren(HeavyMachineGun);
}

if (machineGun) {
bulletGUI.text = machineGun.GetRegularBulletsLeft().ToString();
}
if (heavyMachineGun) {
bulletGUI.text = heavyMachineGun.GetHeavyBulletsLeft().ToString();
}

Does your script compile? The reason I ask is that MachineGun, RocketLauncher and HeavyMachineGun are not valid variable types.

You would have to declare the variables like this:

private var machineGun : Transform = null;
private var rocketLauncher : Transform = null;
private var heavyMachineGun : Transform = null;

function Awake() { 
    machineGun = GetComponentInChildren(MachineGun); 
    rocketLauncher = GetComponentInChildren(RocketLauncher); 
    heavyMachineGun = GetComponentInChildren(HeavyMachineGun); 
}

function Update() {
    if(machineGun != null)
        bulletGUI.text = machineGun.GetRegularBulletsLeft().ToString();
    if(heavyMachineGun != null)
        bulletGUI.text = heavyMachineGun.GetHeavyBulletsLeft().ToString();
}