Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question How to convert string to text?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Felix3749, Jul 2, 2023.

  1. Felix3749


    Oct 15, 2022
    This is my script that is assigned to Text (Legacy):

    using UnityEngine;
    using System;
    using UnityEngine.UI;

    public class Text : MonoBehaviour
    public long score;
    Text output;

    void Start()
    output = GetComponent<Text>();
    output.text = "Score: " + score;

    The UI should then display "Score: score". I am using the Unity 2021.3.22f1 Personal <DX11> version. I am a beginner. The error of this script is error CS1061(it is market red).

    Thanks in advance for any help.
  2. DuckDuckDev


    Sep 7, 2018
    Thread is kinda old but nobody replied to you so I figured I'd answer. It's likely because GetComponent<Text> didn't find anything. Just to test this you can make it a serialized field and set the value in the editor.