- Home /
Question by
TheGamingBurrito · Jul 15, 2014 at 07:11 PM ·
javascriptammo
Help with ammo script :)
Ok so i am a bit of a noob when it comes to coding, but i made this ammo script, however when ever i shoot the number does not go down, can anybody help?
var Ammo = 20;
var MaxAmmo = 20;
var AmmoPool = 100;
if (Input.GetButtonDown ("Fire1")) {
Ammo--;
}
if (Input.GetButtonDown ("r")) {
Ammo++;
AmmoPool--;
}
function OnGUI () {
GUI.Box( Rect(10,10,100,90), Ammo.ToString() );
GUI.Box( Rect(40,10,100,90), AmmoPool.ToString() );
}
Comment
Best Answer
Answer by YoungDeveloper · Jul 15, 2014 at 07:16 PM
This will start you going.
private var ammo_mag:int = 5;
private var ammo_all:int = 10;
function Update(){
if (Input.GetButtonDown ("Fire1")){
if(ammo_mag > 0)ammo_mag--;
}
if (Input.GetKeyDown(KeyCode.R)) {
Reload();
}
}
private function Reload(){
if(ammo_mag == 0){
if(ammo_all > 0){
ammo_all -= 5;
ammo_mag = 5;
}
}
}
function OnGUI () {
GUI.Box( Rect(10,10,70,25), ammo_mag.ToString() +"/"+ammo_all.ToString() );
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to make a selection system? 1 Answer
How to spawn objects in a specific range of random location 1 Answer