Unity C# 2D 游戏编程问题。

问题遇到的现象和发生背景

如图,生成的五张卡牌的thiscard数值不知道为什么是一样的

img

img

我是通过用把标签改成clone来实现不同卡获得不同数值

img

用代码块功能插入代码,请勿粘贴截图

这是卡牌上的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class ThisCard : MonoBehaviour
{
public List thisCard = new List();
public int thisId;

public int id;
public int shang;
public int xia;
public int zuo;
public int you;

public int num;

void Start()
{
    thisCard[0] = CardDataBase.cardList[thisId];
    num = CreatCard.decksize;
}

void Update()
{
    id = thisCard[0].id;
    shang= thisCard[0].shang;
    xia = thisCard[0].xia;
    zuo = thisCard[0].zuo;
    you = thisCard[0].you;
    if (this.tag == "Clone")
    {
        thisCard[0] = CreatCard.staticDeck[num - 1];
        num -= 1;
        CreatCard.decksize -= 1;
        this.tag = "Untagged";
    }
}

}

这是生成卡牌的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CreatCard : MonoBehaviour
{
public List deck = new List();
public static List staticDeck = new List();
[SerializeField] private GameObject CardPrefab;
[SerializeField] private Sprite[] CardImage;

private int CardsNum = 0;
public int x;
public static int decksize;
bool exist;
int[] wyf = { 22, 22, 22, 22, 22};
void Start()
{
    CardsNum = 0;
    int[] wyf = { 22, 22, 22, 22, 22 };
    decksize = 5;
    x = 0;
   while (CardsNum < decksize)
    {
        x = Random.Range(0, 22);
        exist = ((IList)wyf).Contains(x);
        while (exist)
        {
            x = Random.Range(0, 22);
            exist = ((IList)wyf).Contains(x);
        }
        deck[CardsNum] = CardDataBase.cardList[x];
        GameObject newCard = Instantiate(CardPrefab);
        newCard.transform.position =
        new Vector3(CardsNum * 208 - 415, -796, -2);
        newCard.GetComponent().sprite =
        CardImage[x];
        wyf[CardsNum] = x;
        ++CardsNum;
    }
}

void Update()
{
    staticDeck = deck;
}

public void Shuffle()
{
    var cube = GameObject.Find("Card(Clone)");
    while (cube)
    {
        DestroyImmediate(cube);
        cube = GameObject.Find("Card(Clone)");
    }
    Start();
}

}

我的解答思路和尝试过的方法

卡的数值是存储在CardDataBase里的哈。
发现如果把卡牌生成数改成1,使用按键点击,逐个生成5张卡牌,数值就没错了()

我想要达到的结果

但是有什么办法让他一次性直接对应五张牌的数值吗()

第一个代码中的thisId都是0呀,所以每次取值thisCard[0] = CardDataBase.cardList[thisId];都是一样的,然后在Update中的赋值也都是一样的。在生成牌的时候获取组件将thisId的值修改一下,就可以了