Hello, following the rcommendation of another user, i’m trying to make a class managing 3D texts and textmeshes. So far, i’ve managed to successfuly add a textmesh and edit it in runtime. But textmesh being a component i need a text3d to attach it to. And this is where the problem arises :
Text3D being a GameObject, i tried instantiating it, but so far i’ve only got the wrong parameter error message. Can anyone explain to me how to add a Text3D to a scene in runtime? Or at least a link to a page explaining it, because i couldn’t find any till now (but will try to).
If you need to instantiate the 3d-text and set its text then you can do something like this:
var textPrefab : GameObject;
var textString : String = "My text";
var textPosition : Vector3;
function OnCreateText () {
var text3d = Instantiate(textPrefab, textPosition, Quaternion.identity);
text3d.GetComponent(TextMesh).text = textString;
}
// C# version
public GameObject textPrefab;
public string textString = "My text";
public Vector3 textPosition;
void OnCreateText () {
GameObject text3d = (GameObject)Instantiate(textPrefab, textPosition, Quaternion.identity);
text3d.GetComponent<TextMesh>().text = textString;
}