- Home /
Generating Random Numbers on a Game Object
Specifically, I want to make a script that prints a random number (1-10) onto a cube game object. Afterwards, these numbered cubes would be instantiated; in other words, I want to make a script that generates numbered cubes, and the numbers on the cubes are randomized and can be accessed through code (Javascript).
My thought process is to make a 3D text game object and then have the cube be the parent of that game object. However, how do you access and edit the text of the 3D text object in code?
Thanks.
Answer by sharpshot124 · Dec 13, 2012 at 02:10 AM
public GameObject textGameObject;
string text = (int)(Random.Value * 10).ToString();
taxtGameobject.GetComponent< TextMesh >().text = text
this should work if im not mistaken but i havn't tested it
Your answer
Follow this Question
Related Questions
Insert 3d text to the front face of a cube GameObject 0 Answers
Putting text on a 3D object? 3 Answers
Text Mesh Pro is not displaying the text as I input it 1 Answer
Why does this text not equal the game object's name? 1 Answer
TextMeshPro 0 Answers