using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomTest : MonoBehaviour
{
private void Start()
{
List<int> rdlist = GetRandomList(3);
for(int i=0;i<rdlist.Count;i++)
{
Debug.Log(rdlist[i]);
}
}
private List<int> GetRandomList(int count)
{
int[] lt = new int[] { 1, 3, 5, 7, 9, 2, 4, 6, 8, 10 };
List<int> rdlist = new List<int>();
for(int i=0;i<lt.Length;i++)
{
rdlist.Add(lt[i]);
}
while(rdlist.Count>count)
{
rdlist.RemoveAt(Random.Range(0, rdlist.Count));
}
return rdlist;
}
}
運行效果: