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 reloadTime = 0.5;
var ammoCount = 20;
private var lastShot = -10.0;
function Fire ()
{
// Did the time exceed the reload time?
if (Time.time > reloadTime + lastShot && ammoCount > 0)
what does Time.time represent???
What does && do to the code???
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
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.