This is my first post and I need help with getting a ammo count that will decrease every time a bullet is fired. I would aslo like to get a reload function that would sutract from a clipsLeft var and reset the ammo var. this is what I have so far.
`var projectile : Transform;
var shootSpawn : Transform;
var ammo : int = 6;
var clipsLeft : int = 10;
function Update () {
if (Input.GetButtonDown("Fire1")){
if (Ammo > 0){
clone = Instantiate(projectile, shootSpawn.position, shootSpawn.rotation);
Physics.IgnoreCollision(clone.collider, collider);
//This is the subtraction function that I'm having trouble with.
ammo -= 1;
} else {
print("Reload");
}
}
}`
If anyone could answer using Java Script it would be much appreciated!!!
var projectile:Transform;
var shootSpawn:Transform;
var clipsLeft:int = 10; // how many clips the player has
var clipSize:int = 6; // how many bullets in 1 clip
private var ammo:int; // how many bullets left in the current clip
function Start() {
ammo = clipSize; // Start with this many bullets.
}
function Update() {
if(Input.GetButtonDown("Fire1")) {
if(ammo > 0) {
var clone:Transform = Instantiate(projectile, shootSpawn.position, shootSpawn.rotation);
Physics.IgnoreCollision(clone.collider, collider);
ammo--; // Subtract 1 bullet
if(ammo <= 0)
Reload(); // Do you want to call reload here...
}
else {
Reload(); // ...or here?
}
}
}
function Reload() {
if(clipsLeft > 0) {
clipsLeft--;
ammo = clipSize;
// Play sound/animation ?
}
else {
// No more clips left...
}
}