- Home /
Random Text to Text Mesh?
Hi, i want to make Key-Cards in my game and have different codes on them, so i made a code, the code generates a random text and should put it on a text mesh, here is the code: function Start() { var text = ""; var length = 10;
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0;i < length; i++)
text += possible.charAt(Mathf.floor(Mathf.random() * possible.length));
GetComponent(TextMesh).text = text;
}
it seems like it doesn't work, help please.
THX lixpoxx
Comment
Best Answer
Answer by robertbu · Aug 15, 2013 at 05:57 PM
Try this:
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var length = 10;
function Start() {
var text = "";
for( var i=0;i < length; i++)
text += possible[Random.Range(0, possible.Length)];
GetComponent(TextMesh).text = text;
}
Your answer
Follow this Question
Related Questions
How to generate prefab with random number inside it ? 1 Answer
How can I change textmesh to a random text snippet? 1 Answer
Randomly generated number 0 Answers
Sound playing at random. (JS) 2 Answers