Unity C# - How to change UI text

Поділитися
Вставка
  • Опубліковано 25 жов 2024

КОМЕНТАРІ • 12

  • @Minecraftrockz2000
    @Minecraftrockz2000 Рік тому +2

    Very helpful! Couldn't figure out that the component was a TextMeshProUGUI. Thanks!

  • @chillmadude
    @chillmadude 2 роки тому +6

    thanks, i was following an older tutorial to help me learn unity, but i didn't realise that legacy text and textmeshpro were two separate things and got stuck because of it
    ...
    also kinda looks like it was outdated for the legacy text bit too
    ...

  • @warriev6086
    @warriev6086 2 роки тому +3

    I have TextMeshPro installed, but it gives this error?:
    Assets\TextChange.cs(11,12): error CS0246: The type or namespace name 'TextMeshProUGUI' could not be found (are you missing a using directive or an assembly reference?)

  • @Angel-ij4bk
    @Angel-ij4bk 2 роки тому +3

    Thanks this is what I was looking for

  • @drizzith0
    @drizzith0 Рік тому

    Really thank you!

  • @malaktunisky3874
    @malaktunisky3874 2 роки тому

    Perfect! Thank you

  • @impactsport109
    @impactsport109 Рік тому +1

    Thanks you bro

  • @hgokmendigital
    @hgokmendigital 2 роки тому

    Thank you.

  • @kaizo_kaim960
    @kaizo_kaim960 2 роки тому

    👍

  • @raymondhodge1754
    @raymondhodge1754 Рік тому

    this my half brother

  • @raymondhodge1754
    @raymondhodge1754 Рік тому

    lolll

  • @Duros360
    @Duros360 2 роки тому

    Ive followed you tut. and have basically butchered the code to impliment on my own scene. The code I've written works (Basically On Update, if I press space, it adds +1 to an int called Coin, and the text box displays "CoinsValueText.text = "Coins: " + coins;" (So Shows "Coins: 1" for example. If hit space, it changes to 2, so 'everything' is working fine).
    My only issue is I have an error message:
    NullReferenceException: Object reference not set to an instance of an object
    InventoryInt.Update () (at Assets/Scripts/InventoryInt.cs:20)
    (InventoryInt is ofc the script)
    line 20 is
    CoinsValueText.text = "Coins: " + coins;
    I've used your vid to set the text box as a public target:
    public GameObject CoinsValue;
    Tweaked your code:
    public TextMeshProUGUI CoinsValueText;
    On void start i have:
    coins = 0;
    CoinsValueText = CoinsValue.GetComponent();
    Void Update:
    CoinsValueText.text = "Coins: " + coins;
    if (Input.GetKeyDown(KeyCode.Space))
    {
    Debug.Log ("You gain 1 Coin");
    coins ++;
    }
    It seems to be working apart from this error message, but i'm still learning uniy + c#, so id like to know where if gone wrong
    (Full Script)
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using TMPro;
    public class InventoryInt : MonoBehaviour
    {
    public GameObject CoinsValue;
    public int coins = 0;
    public TextMeshProUGUI CoinsValueText;
    void Start()
    {
    coins = 0;
    CoinsValueText = CoinsValue.GetComponent();
    }
    // Update is called once per frame
    void Update()
    {
    CoinsValueText.text = "Coins: " + coins;
    if (Input.GetKeyDown(KeyCode.Space))
    {
    Debug.Log ("You gain 1 Coin");
    coins ++;
    }
    }
    }