I am using unity 3.3 and I am using the FPS tutorial. The tutorial works, but I decided to make the rocket launcher display the ammo in numbers just like the machine gun does. The problem is that when I switch weapons, it always shows the ammo for the rocket launcher.
Here is where the problem is. I think the two if statements below aren’t working right because the rocket launcher part is always executed. Can someone show me how to fix this? Thanks.
function UpdateGUI () {
// Update health gui
// The health gui is rendered using a overlay texture which is scaled down based on health
// - Calculate fraction of how much health we have left (0...1)
var healthFraction = Mathf.Clamp01(hitPoints / maximumHitPoints);
// - Adjust maximum pixel inset based on it
healthGUI.pixelInset.xMax = healthGUI.pixelInset.xMin + healthGUIWidth * healthFraction;
// Update machine gun gui
// Machine gun gui is simply drawn with a bullet counter text
if (machineGun) {
bulletGUI.text = machineGun.bulletsLeft.ToString();
clipGUI.text = machineGun.clips.ToString();
}
// Update rocket gui
// This is changed from the tutorial PDF. You need to assign the 20 Rocket textures found in the GUI/Rockets folder
// to the RocketTextures property.
if (rocketLauncher) {
//rocketGUI.UpdateRockets(rocketLauncher.ammoCount);
bulletGUI.text = rocketLauncher.ammoCount.ToString();
}
}