Hello everyone !
I am a bit a beginner in using Unity and C#, watched/followed some vid’s tutorials and decided to make the first step of making my card game.
But I have a probleme when I instantiate my cards in a “for loop”. Here is the code :
public class CreatingCards : MonoBehaviour
{
public GameObject peopleCard;
public GameObject samouraiCard;
public GameObject oldMadManCard;
public GameObject deck;
private Text peopleCardText;
private Text samouraiCardText;
private Text oldMadManCardText;
public List<GameObject> cards = new List<GameObject>();
void Start()
{
for (int i = 1; i <= 18; i++)
{
GameObject peopleCardInstantiated = Instantiate(peopleCard, new Vector3(0, 0, 0), Quaternion.identity);
peopleCardInstantiated.transform.SetParent(deck.transform, false);
peopleCardText = peopleCard.GetComponentInChildren<Text>();
peopleCardText.text = i.ToString();
peopleCardInstantiated.transform.position = deck.transform.position;
cards.Add(peopleCardInstantiated);
Debug.Log(i);
}
}
}
The thing is when I add the card in my cards’ list the first one is the 18th then 1, 2, 3, 4, …
And so in my GameObject Deck, the first one is also the 18th,
So I really don’t understand why is it doing like this because inside the Log I can see he finished with the i = 18.
Thanks in advance for responding me !
Have a good what you want haha