I have a simple counter in my office scene that adds up the cost of damage the player causes each time they break anything made of glass, e.g. doors, windows etc. Each pane of glass has the following script on it which is called when the glass breaks:
var countText : Text;
private var count : int;
function SetCounter() {
count = count + 350;
countText.text = "Damage Bill: $" + count.ToString();
}
This works fine, and it tallies up the damage nicely, but the player also has the option to drop mines to eradicate the enemy, and I have the same script called by the mines when they explode, accessing the same Text, but if there is already a tally in the UI, when the mine destroys any glass, it resets the count from zero - vice versa if a mine does any damage first and starts the count, and then the player breaks a window - again the count restarts from zero, listing just the damage amount of the window. The windows tally up one after another no problem as they’re broken, but when I call the same script from the mine explosion, the reset occurs.
The only difference is in the way the scripts are called; the windows do it directly as they are already in the scene, and the mines, being instantiated prefabs, call the script from an existing empty gameobject which has the same script on it.
Any idea what I am doing wrong here? Thanks for any/all replies.