unity创建一个数组,让他随机生成一个东西之C#语言(有图教程)
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();
}
}

把代码拖到按钮上,然后绑定内容,运行就可以输出.
本文来自博客园,作者:AlanDu,转载请注明原文链接:https://chuna2.787528.xyz/AlanDu/p/8025598.html

浙公网安备 33010602011771号