Random Card Generator With Unity(C#)

Random Card Generator With Unity(C#)

Mr. Unity Buddy's photo
Mr. Unity Buddy

Published on Apr 6, 2021

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Hello Buddies! Have you ever think about how to make a game with a Random Card Generator? Well, I thought about that. We can make a game based on Randomly Generated cards. Get ready with your project!

Joke Of The Day

image.png

Set Up Your Scene

  • First make some panels and give some names (Blue, Red, Green or 'Eiffel', 'Tajmahal' something like that)
  • Replace them all in a one place.
  • Make a button as 'Go' and create a script 'Random Generator' image.png

Random Card Generator

In the script,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RandomColrGenerator : MonoBehaviour
{
    public List<GameObject> cards; // Make a list of Cards


    GameObject picked = null;

    public void Generator()
    {
        picked?.SetActive(false); // Deactivate Other GameObjects
        picked = cards[Random.Range(0, cards.Count)]; // Get a random Card from the list of Card
        picked.SetActive(true);  // Activate only Randomly generated card

    }

}
  • Now make a empty GameObject called 'RandomGenerator' and add your script.
  • In button, make function as 'Generator'.

image.png

Now you have a Random Card Generator!

Conclusion

We made a Random card Generator. This can be used for a educational game too. Like, A card with a Famous location will be appear and the Player have click the button has the name of Country it has located. Good luck and see you, buddies!

 
Share this