Scripting win screen at end of game

Hi all,

I’m new to coding and have come across a problem I dont understand. I made a script for collecting an object and gaining a score from it. That part works fine. But I’d like it to update so that when the score equals a certain amount, my in game scene will change to my win scene. I’ve tried (see below) but it doesn’t seem to be working. Although no errors come up. Any help is much appreciated:) Screenshot included too

using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.SceneManagement;
///


/// This script allows player to collect hearts and gain score
///

public class CollectHeart : MonoBehaviour
{
public AudioSource collectSound;
void OnTriggerEnter(Collider other)
{
collectSound.Play();
ScoringSystem.theScore += 10;
Destroy(gameObject);
}
public void Update()
{
if (ScoringSystem.theScore == 60)
{
SceneManager.LoadScene(“winScene”);
}
}
}

You are destroying the gameobject so chances are your update code never gets executed when the variable is equal to 60.

You could check if the score is high enough before destroying and only destroy if it is lower or do the logic in the ScoringSystem class. You could use a property or a method to update the score.