using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Choice : MonoBehaviour { public Text tips; // Use this for initialization void Start () { } public void ChioceBtnEvent() { string[] NameArray = new string[] {"001婷婷", "002贺堂", "003 莹","004润生","005满想","006 鑫", "007丽叶","008梦怡","009燕杰","010小华","011维豪","012朋", "013梦凡","014银利","015玉娣","016剑锋","017 龙","018 宁", }; int a = Random.Range(0,18); tips.text = "结果是:"+"\n"+NameArray[a].ToString(); } }
把代码拖到按钮上,然后绑定内容,运行就可以输出.