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;
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.