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

时间:2017-12-12 01:07:17   收藏:0   阅读:4009
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();
 
 
    }
     
}

  技术分享图片

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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!