unity创建一个数组,让它随机输出数组里的东西

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();
 
 
    }
     
}

  技术分享图片

把代码拖到按钮上,然后绑定内容,运行就可以输出. 

文章来自:http://www.cnblogs.com/Du652597991qq/p/8025664.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3