Question by
Avi3ator · Nov 19, 2016 at 08:09 PM ·
scripting problemchange
Random Text String
I want to make it when you press a button it give us a "pre random" text, so like if u press it, it would say "player1" or "player6" or "player2"
i made a code for random numbers but i wanna change it to string...
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class Knowledge : MonoBehaviour
{
public Font myFont;
float randomNumber;
public void randomNumbers()
{
randomNumber = Random.Range(0, 10001);
}
void OnGUI()
{
GUIStyle myStyle = new GUIStyle();
myStyle.font = myFont;
GUI.color = Color.yellow;
GUI.Label(new Rect(600, 200, 500, 500), randomNumber.ToString(), myStyle);
}
}
Comment
Answer by studioAdam · Nov 19, 2016 at 10:12 PM
Hi @Avi3ator. Try adding a string in there like this:
GUI.Label(new Rect(500, 200, 500, 500), "Player " + randomNumber.ToString(), myStyle);
Your answer
![](https://koobas.hobune.stream/wayback/20220612101007im_/https://answers.unity.com/themes/thub/images/avi.jpg)