TMP Text changing issue

The following code will not change the TMP_Text “ScoreText” to what it should. I have also tried using ScoreText.Equals("testText"); but that also wont change the text. All of the other code works fine. Any solutions?

using System.Collections;
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using TMPro;

public class LogicScript : MonoBehaviour
{

    public GameObject pin;
    public int pickPosition;
    public CapsuleCollider2D pickCollider;
    public CapsuleCollider2D pinCollider;
    public int Score = 0;
    public TMP_Text ScoreText;

    // Start is called before the first frame update
    void Start()
    {
   
    }

    // Update is called once per frame
    void Update()
    {
   
        if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
        {

            if (pickCollider.bounds.Intersects(pinCollider.bounds))
            {
                print("success");
                Score = Score + 1;
                ScoreText.Equals(Score);
            }
            else
            {
                Score = 0;
                print("fail");
            }
        }
        pinPositionSetter();
    }

9143341--1270450--Image.png

Where did you get the idea that Equals would change anything? Equals is a method in C# that checks two objects for equality (Object.Equals Method (System) | Microsoft Learn). That’s completely irrelevant here.

You want something like:
ScoreText.text = Score.ToString();

1 Like

I got the idea that Equals changed things because the character “=” sets what something is and “==” checks the value of something. Not saying it’s rational, but since you are asking where I got the idea for it I thought I would explain.
After making the change it works. Thanks for helping!

1 Like

Every C# object has a .Equals method which is used for determining equality: https://learn.microsoft.com/en-us/dotnet/api/system.object.equals?view=net-7.0

Your IDE should show that it returns a boolean value, which should help indicate its purpose.