Hey all,
I’ve been tinkering around a tiny scavenging system for a game i’m working on - at this moment. All it i supposed to do is add a certain amount of food/scrap to a value in my gameplayglobals script if i press the scavenge button while inside the triggerzone attached to a crate - and then destroy the crate.
It works, i get (in this case food) added to my globals - BUT i get it added about 22 times, instead of just adding one “portion” of 1-4 food.
var IsFoodContainer : boolean = false;
var IsScrapContainer : boolean = false;
static var FoodAmount = Random.Range(1,4);
static var ScrapAmount = Random.Range(1,5);
function OnTriggerStay (other : Collider) {
// IF player scavenges while in zone
if (Input.GetButtonDown ("Scavenge")&& IsFoodContainer == true){
AddFood();
}
// If player rolls 2, roll amount, and goto addscrap,
if (Input.GetButtonDown ("Scavenge") && IsScrapContainer == true){
AddScrap();
}
}
function AddFood(){
GameplayGlobals.foodAmount += FoodAmount;
Debug.Log("ADDED FOOD"+FoodAmount);
Destroy(gameObject);
}
//////////////////////////////////////////////////////////////////////////////////////
function AddScrap(){
GameplayGlobals.scrapAmount += ScrapAmount;
Debug.Log("Added SCRAP"+ScrapAmount);
Destroy(gameObject);
}
I really hope someone can help me here - i’ve tried all the different “Input.GetButton” variations (up/down) - tried rearranging the code in different matter. I’ve been staring blindly at the code for a while now. So I hope someone knows what to do:)
Thanks in advance.
Lasse