- Home /
How can I Include string variables in Rich Text?
I'm finishing up my game and I'm trying to set up the death screen that displays high scores. I think it would be easiest to use Rich Text on my GuiText.
Is there any way I can add a string variable to my Rich Text?
Thanks
I'm not sure that your question makes sense. What do you mean by 'Is there any way I can add a string variable to my Rich Text'? What is a Rich Text?
Rich Text is a kind of HT$$anonymous$$L style markup that can be used within unity. You can use tags to alter the text. I was wondering if there was anyway to use some kind of a variable tag to add a string variable on to the end of my text. :)
So you're talking rtf? Is this on a web page or in unity? If in unity, are you using a plugin? I don't think that you've provided enough context for others to understand what your use case is. Is it a web build, mobile or standalone? I'm not familiar with using rtf in unity.
Ok. Now that I'm on a computer I'm looking and it seems that, yes it'd be easy to do. Sorry for asking too many questions. I'll work on an answer now. :)
Answer by iwaldrop · Jan 08, 2014 at 03:35 AM
This is a very contrived example of how to use a variable with GUIText and Rich Text. Essentially, there is nothing really different. You just need to include the tags.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(GUIText))]
public class RichTextDemo : MonoBehaviour
{
const string EXAMPLE_TEXT_BASE = "This is a <b>{0}</b> of using variables with <i>{1}</i>.";
const string EXAMPLE_TEXT_BASIC = "basic";
const string EXAMPLE_TEXT_RICH = "Rich Text";
void Awake()
{
GUIText text = GetComponent<GUIText>();
string joined = string.Format(EXAMPLE_TEXT_BASE, EXAMPLE_TEXT_BASIC, EXAMPLE_TEXT_RICH);
text.text = joined;
}
}
Your answer
Follow this Question
Related Questions
String to Var 2 Answers
Inputfield set as Variable 1 Answer
Optimizing OnGUI 1 Answer
Display additional text before the variable that the user is editing in a GUI Text Field 1 Answer