Hi guys, When I pick up the ammo on the table they are destroyed but the variable amount is not added to the variable that determines the ammunition clips that I have. HELP ME
var obj1 : Transform; //the gameobject (Ammo)
var obj2 : Transform; //my Player
var Bar : float;
var amount = 60; //number of clips what I will add to the var clips
function Start ()
{
var Bar = (Screen.width / 1);
}
function Update()
{
var dist = Vector3.Distance( obj1.transform.position,obj2.transform.position );
//if distance is < 4
if(dist < 4)
{
if(Input.GetKeyDown ("f")) //if I press f
{
AddClip(); //Go to function AddClip
}
}
}
function OnGUI() //function for Gui
{
var dist = Vector3.Distance( obj1.transform.position,obj2.transform.position );
if(dist < 4)
{
GUI.Box (new Rect(10, 740, Bar, 40), "Ammo for M4A1, F to pickup");
}
}
function AddClip ()
{
var ammo : gunscript = GetComponent(gunscript); //
if (ammo) // Add Clip to to the var clips in the script "gunscript"
ammo.clips += amount; //
WaitForSeconds(1);
DestroyClip(); //after addedclip destroy the gameobject ammo
}
function DestroyClip()
{
Destroy(gameObject);
}
//and this is the variable clips in the script "gunscript"
//var clips : int = 20;
//the variable clips are the clips in the M4A1 for reloading