I created a script to display how long the player has played my game.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class Stopwatch : MonoBehaviour
{
    bool stopwatchActive = false;
    float currentTime;
    public Text currentTimeText;
    
    // Start is called before the first frame update
    void Start()
    {
        currentTime = 0;
        StartStopwatch();
    }
    // Update is called once per frame
    void Update()
    {
        if (stopwatchActive == true)
        {
            currentTime = currentTime + Time.deltaTime;
        }
        TimeSpan time = TimeSpan.FromSeconds(currentTime);
        currentTimeText.text = time.Seconds.ToString();
    }
    public void StartStopwatch()
    {
        stopwatchActive = true;
    }
    public void StopStopwatch()
    {
        stopwatchActive = false;
    }
}
I assigned everything and tested it. Everything works perfectly fine, but I get this error in Unity:
NullReferenceException: Object reference not set to an instance of an object
Stopwatch.Update () (at Assets/Scripts/Other/Stopwatch.cs:28)
(I get no error in VS)
Is there something wrong with the code?
(Sorry if it is a dumb mistake, because I am new to scripting)
 
    