# What does the ammo count script mean ???

Hi im a beginner with Unity 3D and i'm trying to learn the scripting language(JavaScript). There are a few things i did not understand in the Following ammo count script

``````var projectile : Rigidbody;
var initialSpeed = 20.0;
var ammoCount = 20;
private var lastShot = -10.0;
function Fire ()
{
// Did the time exceed the reload time?
if (Time.time > reloadTime + lastShot && ammoCount > 0)

``````
1. what does Time.time represent???
2. What does && do to the code???
3. Mathematically reloadTime(0.5) + Last shot(-10) would always be a negative number right???

Also at the end of the script there a line sayin

``````lastShot = Time.time;

``````

ammoCount--;

What does this mean????

I dont feel like goin ahead without understanding the scripts.... Hopeing to fine help soon thanx... cheers

The time this frame has started (Read Only). This is the time in seconds since the start of the game.

&& Means and, just like || means or. So for that if statement to run, both conditions on the sides of the && must be true.

``````Time.time > reloadTime
//and
ammoCount > 0

``````

For that math equation, maybe someone else can answer, I'm horrible with math... Let along stuff I haven't read up on =).

``````lastShot = Time.time;

``````

This is saying that the last shot was shot at the current time.

``````amouCount--;

``````

This makes the ammoCount variable decrease.

``````var i = 5;
//i=5
i--;
//i = 4
--i;
//i = 3
i++;
//i = 4
++i;
//i = 5

``````

Does that make sense?

Keep this up =) You're actually trying unlike some people here haha.

if (a>b) means if (a is larger then b), < means smaller.

= and <= mean is smaller/bigger or equal to.

so if (Time.time > 5) will trigger AFTER 5 seconds, if (Time.time >= 5) will trigger AT 5 seconds.

a = 5 sets a to 5.

Often you want to not change the value of a completely but add/decrease it. This would be a = a + b. Shorthand for this is a += b.

Also often you just want to add/decrease it by one. This would be a += 1. Shorthand for this is a++.

Yep - programmers are lazy. ^.^

Maybe what I'm adding is useless but I read about the math equation and it look very similar to a syntax I use for timers. The lastShot line is related to it, it is increased at every run. Here's how I do it:

``````var atkDelay:float = 1;  //delay between the attack
var nextAtk:float = 0;   //minimum Time.time where the next attack can occur

function Update(){

if(Time.time>nextAtk){
nextAtk = Time.time+atkDelay;  //minimum Time.time = Now + our delay
//Attack("!!!");
//DoMoreStuff();
}

}

``````

Everytime the if() block occurs, the nextAtk is set to atkDelay later. That is what happens in your code, with the added verification that you also owns ammo.

Though it seems pointless to declare lastShot as -10, as I believe it will have the same effect as 0.