Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 防止代码以随机顺序显示同一图像?_C#_Unity3d - Fatal编程技术网

C# 防止代码以随机顺序显示同一图像?

C# 防止代码以随机顺序显示同一图像?,c#,unity3d,C#,Unity3d,我制作了一个脚本,每X秒显示一次列表中的随机图像,但有时它会在几个小时的游戏过程中显示相同的图像。我想知道如何才能让它不显示当前游戏中已经显示的图像。这是我的密码: void Start () { // start count StartCoroutine(RandomReportEvent()); } xx 任何帮助都将不胜感激 我建议你列一个所有图像的列表,随机化列表的顺序,然后循环浏览。当你到达终点时,你可以重新洗牌或者只是重新开始相同的序列 您可以找

我制作了一个脚本,每X秒显示一次列表中的随机图像,但有时它会在几个小时的游戏过程中显示相同的图像。我想知道如何才能让它不显示当前游戏中已经显示的图像。这是我的密码:

void Start () {

        // start count
        StartCoroutine(RandomReportEvent());

}
xx


任何帮助都将不胜感激

我建议你列一个所有图像的列表,随机化列表的顺序,然后循环浏览。当你到达终点时,你可以重新洗牌或者只是重新开始相同的序列


您可以找到一种很好的方法来在

中洗牌列表或数组。我建议您列出所有图像,随机化列表的顺序,然后循环遍历它。当你到达终点时,你可以重新洗牌或者只是重新开始相同的序列


您可以找到一种很好的方法,在

中洗牌列表或数组。创建一个图像列表怎么样,然后使用
int index=random.Range(0,count)选择一个随机图像
从该列表中删除,然后使用
yourImagesList.RemoveAt(索引)从列表中删除该项因此在下一次迭代中,图像将不可用。您可以更新
int count=memeImg.count的值列表编码>。从列表中删除图像后计数。
资料来源:
和

创建一个图像列表怎么样,然后用
int index=random.Range(0,count)选择一个随机图像
从该列表中删除,然后使用
yourImagesList.RemoveAt(索引)从列表中删除该项因此在下一次迭代中,图像将不可用。您可以更新
int count=memeImg.count的值列表编码>。从列表中删除图像后计数。
资料来源:
和

这似乎是一个更好的解决方案。让我试试看,我会回来的!!非常感谢!!这似乎是一个更好的解决方案。让我试试看,我会回来的!!非常感谢!!
IEnumerator RandomReportEvent(){


        float wait_time = Random.Range (53.5F, 361.2f); // removed 1879.2f

        // test purposes
        // float wait_time = Random.Range (1.7F, 3.2f);

        yield return new WaitForSeconds(wait_time);
        memeWindow.SetActive (true);

        // get random reports number within range
        float ReportValue = Random.Range (1.2F, 57.8F);

        // round to 2 dp
        ReportValue = Mathf.Round(ReportValue * 100f) / 100f;
        // show random report value in Text
        randomReportValue.text = string.Format ("<color=#FF8400FF>{0}K</color>", ReportValue);

        // Show Random Image from list
        showRandomImage();
    }
void showRandomImage(){

        // count the amount of images 
        int count = memeImg.Count;

        // randomly select any image from 0 to count number
        int index = Random.Range(0, count);

        // assing an image from our list
        sr.sprite = memeImg[index];


    }