Candles not getting counted when you click on them

Hello, I’m making a horror game and when you click on the first candle it counts it, but when you click on the second candle it destroys it but doesn’t count it

Here is my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;

public class CandleCount : MonoBehaviour
{
public Text countText;

private int count;

void OnMouseDown()
{
count++;
SetCountText();
Destroy(gameObject);
}

// Use this for initialization
void Start()
{
count = 0;
}

void SetCountText()
{
countText.text = “Candles: " + count.ToString() + " / 15”;
}
}

Do you have that script on every candle?

You need the counter on on a different object. but just one object. Maybe the player?

I do have the script on every candle and I will see what happens when the counter is on the player

Basically with the script on each candle, each candle has an instance of the script, which means each time you collect the candle, it will always set the value to 1, which is why it isn’t working.

So that means you currently have 15 counters that are all set to zero. Here’s what was happening:

When the player clicks the first candle, that candle sets its count from 0 to 1 and updates the UI so it says “1/15”. Now you have 14 counters set at 0 and 1 counter set to 1.

Then that candle destroys itself. At the point you have 14 counters left, each set to 0.

When the player clicks the second candle, that candle sets its count from 0 to 1 and updates the UI so it says “1/15”. Now you have 13 counters set at 0 and 1 counter set to 1.

And so on

So I hope illustrates why it wasn’t working before.

Thank you for taking your time to help me, the candle counting system is working now.

Thank you