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 ...
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?)
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 ++; } } }
Very helpful! Couldn't figure out that the component was a TextMeshProUGUI. Thanks!
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
...
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?)
Thanks this is what I was looking for
Really thank you!
Perfect! Thank you
Thanks you bro
Thank you.
👍
this my half brother
lolll
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 ++;
}
}
}