I have chests that open and give me money. When I open the first chest it gives me 500, but when I open a second chest it is adding the new amount to the original money amount of 0 and I am still left with 500. here is my code please help:
var money : int;
var GUIMoney : GUIText;
var target : Transform;
var moneyAmount : int;
function OnTriggerEnter( other : Collider ) {
if (other.tag == "Player") {
money+= moneyAmount;
GUIMoney.text = money.ToString();
Destroy(other.gameObject);
}
}
function Update(){
MoneyPU();
}
function MoneyPU(){
distance = Vector3.Distance(target.transform.position, transform.position);
if(distance < 2){
if(Input.GetButtonDown("Activate")){
yield WaitForSeconds(1);
money+= moneyAmount;
GUIMoney.text = money.ToString();
Destroy (this);
}
}
}