Check out my books, games and more!

Join our Discord:

Learn how to create a 2D card game in Unity with randomized decks and draggable/droppable cards using the canvas, C# scripting, prefabs, and more!

Continue with Part 2:

Project Git Repository:

Subscribe and like for more!

Take a tour of Unity 2D:

Check out my books and games:

Follow me on Twitter:

Music shout-out: “8bit Blix” by Micah Young

Nguồn: https://thedancingparent.com/

Xem thêm bài viết khác: https://thedancingparent.com/game/

42 Comments

George Maltez

June 28, 2020

This is a great video tutorial. I've learned a lot and hope to improve and create something outstanding. Keep up the great work and thanks for dedicating some time to Unity.

Reply

TheGeneral

June 28, 2020

I don't usually Like videos because of laziness, but this definitely deserves it!

Keep it up m8, looking forward to more easy to follow tutorials!!!

Reply

Randy Ladyka

June 28, 2020

What are the camera settings? I can't seem to get it to match the size of the canvas.

Reply

Andrew M

June 28, 2020

Very good.

Reply

Deniz Tuncer Tepe

June 28, 2020

I can't drop more than one card into drop zone and it goes to everywhere except drop zone it doesn't sets it's position

Reply

Facehunter2003

June 28, 2020

This 3 part series has helped me port over my friends card game to digital. Just mainly had to get the basics for Unity down before I could start scripting the rest of the game.

Reply

Hugo Zaragoza

June 28, 2020

Great tutorial!!! Thanks for the clarity and the pace. Perfect!

Reply

Aryan Trehan

June 28, 2020

Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption
I am getting this error. Any help?

Reply

Luca Laurence

June 28, 2020

Hey Farzan! Really enjoyed the tutorial but I just had a question regarding the dragging and dropping. At first for me it didn't work properly and after some testing, turns out when you enable pixel perfect under canvas, for some reason you are unable to move the cards. Would you know why that's the case?
Anyways, looking forward to seeing the rest of this series!

Reply

n3rd

June 28, 2020

40:35 during this part, when I press the "Draw Cards" button I get an "ArgumentOutOfRangeException" error. I copied the exact same code as the one in the github link, so I have no clue what's causing the error.

Reply

Александр Кавокин

June 28, 2020

Really cool tutorial! Thanks!

Reply

Baturalp K

June 28, 2020

The tutorial is really helpful, thanks mate.

Reply

wancat

June 28, 2020

Don't know if this is new for unity. I get the error:

Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption (GameObject: 'Card1(Clone)'

This is for when the Draw Cards script is run. How do you fix this?

Reply

Nicholas Young

June 28, 2020

Oh my god this video was great, everything i was looking for and more. Subscribing for sure

Reply

Juanu Haedo

June 28, 2020

Hey Farzan. Great tutorial!

Here is the documentation for doing the drop zone detection a different way.
You can do raycasting with the UI library and avoid going to Rigid Body which might be a bit overload for a Canvas based game.

https://docs.unity3d.com/2018.1/Documentation/ScriptReference/UI.GraphicRaycaster.Raycast.html

Having said that, it would be interesting if anyone did some tests on using the Rigid Body vs GraphicsRaycaster to see if by any chance, using the rigid body is more performant… or not.

Reply

Tanzra

June 28, 2020

I want to do this on a website. Does this produce a .exe that someone has to install? I don't know if I'm in the wrong place or not. If I am in the wrong, anyone know what I could use to do that for the web?

Reply

Davis Nicholas

June 28, 2020

Anyone has problem when trying to drag PlayerArea from hierarchy to gameoject?
I am unable to do that. I can drag and drop the prefabs but not the objects from hierarchy?
HELP!!!!!!

Reply

mehmet yalinbas

June 28, 2020

When the number of cards is 4 in the dropzone region, what should we do to avoid accepting more cards even if we put them in that region?

Reply

JJ Lew

June 28, 2020

Thank you for sharing this amazing tutorial – I found it super straightforward and easy to follow along!

Reply

Ravi Rajput

June 28, 2020

This is awesome man!!!

Reply

Magzy Wagzy

June 28, 2020

For anyone else who came here as an extra guide or reference point after setting up a screenspace camera for the canvas, if the drag and drop is making your cards disappear

if (isDragging)

{

transform.position = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);

}

This will fix your drag and drop issue

So far this tutorial is much earlier entry point than the other series i'm following along with, especially with the "no more unity multiplayer" issue fix I see in my recommended side bar

Reply

Sida Ren

June 28, 2020

Amazing tutorial!!! I really want to progress to the next video but my drag and drop isn't working. The problem is when I click the cards it dissapears rather then being able to drag. I have copied the script exactly up to 47:00 and have added the event triggers correctly

Reply

Steve S

June 28, 2020

Super video.

What if you were coding a game like Magic the Gathering. Assume a player's deck has 60 unique cards. Is there a better way than in the script to create 60 public GameObjects, and link them? I suppose you might want a game card manager that serves the GameObjects by Id instead of dragging them into the script like you did for card 1 and 2?

Reply

maxfield H

June 28, 2020

Great tutorial! I feel like just by watching it, it's giving me good insights into the Unity workflow. Which is appreciated, bc as you said, it can be a little overwhelming with all the options!

Reply

Chow Brian

June 28, 2020

I'm completely new to Unity and you covered a lot of the basics in your video! thank you so much for your work and hope to see more coming!

Reply

John Burville

June 28, 2020

Just finished this video and it is awesome. Well done. Cant wait to try the other parts. Thanks so much for putting all this time in.

Reply

John Burville

June 28, 2020

Can I get the code?

Reply

Matthew Hudetz

June 28, 2020

So when I try typing "GameObject" in the scripts, it doesn't turn blue like yours and it isn't an option to pick. Just doing object works though so I don't know if I'm in the wrong version or not. Also, if I'm in the wrong edition, does object still work?

Reply

ben currie

June 28, 2020

Thanks for the video! When I am creating the canvas it is only doing it with a width of 640 and a height of 480 and won’t let me change the values. Any reason why?

Reply

rednaxelA1122

June 28, 2020

This is a great video, it's easy to follow. Although, I had a problem when I tried assigning a colour to the background and areas, it would just remain blank. Any ideas? I'm running Unity 2019.3.10f1.

Reply

Greg Galloway

June 28, 2020

I really wanted to like the tutorial, but the text size was so small with so little contrast that I couldn't read it 🙁
Would have been excellent otherwise.

Reply

Tianhao Zhang

June 28, 2020

28:51 I followed all the steps but it still won't display the card, it still produces clones outside the canvas.

Reply

Jadandlud

June 28, 2020

Getting an error here. "The name 'i' does not exist in the current context."

Reply

Giorgos Markos

June 28, 2020

when i type gameobject on visual studio it doesnt come as a highlited command.What should i do

Reply

Panagiotis Mourlas

June 28, 2020

This tutorial is amazing.Clear instructions and exactly the kind of thing I have been looking for! Thank you and keep up the good work!

Reply

DenglishDesigner

June 28, 2020

This was exactly the "basic UI for card games" kind of tutorial I was looking for! Thanks!

Reply

Zhaoyin Qin

June 28, 2020

Thanks, very helpful!

Reply

احسان زارعی

June 28, 2020

Hey farzan . first ty so much cuz during this tutorial i learned a thing that i need alot .second ,if i wanna make a uno game ,should i create 52 prefab card and enter them to a list ? for uno i need remove those cards when given to player ,how can i do this ?

Reply

Gustavo Hernandez

June 28, 2020

Hello Amazing tutorial, but i been having a problem did everything as explain but for some reason the drag and drop is not working.

Reply

dimwood2011

June 28, 2020

M. S. Farzan i know you have probably moved on to other projects but i do have a question if you have time to respond. I understand random range between the red card and the green card.My question is if i wanted one deck for one player game like solitare would i need to create 52 individual cards for this with the same script on each individual card? thanks i hope that makes sense

Reply

Tashenea Burns-Young

June 28, 2020

Hey my code doesn't work i am trying to figure out why unity is saying that i need to use using static?? Can you help with that?

Reply

devtodev

June 28, 2020

26:00 from what I understand from general OOP and C#, the script you created by clicking on add component is independent/reusable code. That means the script is not encapsulated within the button object but just attached to it and that also means, you can reuse that script in any other game object. For rexample, create a 3d model of dealer and attach the script to it.

Reply

Leave a Reply