Textmeshpro not being responsive

alright so here’s the thing, i have these two trigger box colliders, when i touch one i want my score to go a point lower, when i touch the other i want it to go a point higher
the negative one works just fine, but for some reason the other doesn’t

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

public class PUNTEGGIO : MonoBehaviour
{
    public GameObject canvasObject2;
    public GameObject canvasObject;
    public float duration = 2f;
    public float Score;
    public GameObject panelObject;
    [SerializeField] TextMeshProUGUI ScoreText;
    // Start is called before the first frame update
    void Start()
    {
        Score = 5;
    }

    // Update is called once per frame
    void Update()
    {
        if(Score <= 0)
        {
            YouWin();

        }
    }
 
    void YouWin()
    {
        canvasObject2.SetActive(false);
        canvasObject.SetActive(true);
        panelObject.SetActive(true);
        ScoreText.text = "You lose!";
        Time.timeScale = 0f;


    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            Addscore();
        }

    }

    void Addscore()
    {
        Score--;
        ScoreText.text = Score.ToString();
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;


public class POWERUPPLUS : MonoBehaviour
{
    public GameObject playa;
    PUNTEGGIO punteggio;
    public int points;
    public GameObject pickupEffect;
    public float duration = 4f;
 
    // Start is called before the first frame update
 
    void Start()
    {
        punteggio = playa.GetComponent<PUNTEGGIO>();

    }

    void OnTriggerEnter(Collider other)
    {
        {
            if (other.CompareTag("Player"))
            StartCoroutine(Pickup(other));
        }
    }

    // Update is called once per frame
    IEnumerator Pickup(Collider player)
    {
        Instantiate(pickupEffect, transform.position, transform.rotation);
        punteggio.Score++;
        GetComponent<MeshRenderer>().enabled = false;
        GetComponent<Collider>().enabled = false;
        Destroy(gameObject);
        yield return new WaitForSeconds(duration);
     
    }
}

I can’t see anywhere that you update your UI text after you call “puntegfio.Score++;” which is why you’re UI is not changing.

I would try to simplify your method for changing score. Instead, maybe something like:

public void ChangeScore(int amount)
{
    score += amount;
    scoreText.text = score.ToString();
}

Call that method when you want to add to the score, or take away, passing in amount as your argument.

@ItzChris92 hit the key point of your score. You don’t ever update the text, which interesting enough you did in your AddScore method. But the suggestion above is a good one.

But a couple things I’d like to mention…Your coroutine as written doesn’t serve a purpose as a coroutine. Your wait is at the end of the coroutine, thus nothing actually “waits”. Your code runs and then waits for no reason.

Also, just a design suggestion, class names shouldn’t be all caps. While this isn’t going to change how your code runs and maybe you did this to help yourself, it’s not normal design practice.

hey guys sorry for the late reply

@ItzChris92 wait, wait, sorry i’m kind of confused
how do i update the UI text from a script to the other? i just noticed (probably should have said that before sorry lmao) the Score of the PUNTEGGIO script doesn’t even change in the inspector, so i suppose i should somehow find and reference instead the float Score from the PUNTEGGIO script but how?

I posted a question about various ways to handle UI as you want it to be as decoupled as possible. I.e your score script shouldn’t “know” that your UI exists.

I decided the best route to do this would be through delegates and events. Give those some research, and have a go at producing something simple with a score and score text box. Any issues then post what you tried here again and I’ll gladly help