- Home /
How to only allow one gameobject to enter a panel
(Edit since my following paragraphs were a bit lengthy. TLDR; I want my panel to only except one gameObject at a time instead of multiple.)
I'm creating a battle card game, and right now I have 2 panels -- one that represents the player's hand, and the other that represents the tabletop where the player would place a card. So far, I have it that the player is able to click and drag cards from their hand to the tabletop (which in the future will initiate an attack), but as of now they're able to put any amount of the cards they wish into the tabletop panel, when I only want one to be allowed at a time. I'm somewhat new to unity, so I'm not sure where to start.
I have 4 scripts so far: One that makes up my Scriptable Object card, another that's for what's displayed on the card (such as names, stats, etc.) , another for the cards that give me the ability to drag them into either panel, and a final one for the tabletop panel that allows me to insert a card from my hand.
I wasn't sure which script would be needed so I didn't copy them over in case they weren't necessary, but feel free to ask me if they're needed!
Thank you for any help you can offer.
Answer by Steyo · Sep 10, 2020 at 01:18 PM
Feel free to post your Drag and Drop code, it seems it would be the most needed. I'm not sure I understand you problem so let's me rephrase it : You have cards in you hands, and you can put a card from you hand to one slot of your board. However, currently you can put several cards in the slot while you only want one.
So let's imagine (because I don't know what your game looks like, but I will pretend it's a Yu Gi Oh display) : 1) You create a script your slots pannel 2) For each slot on your pannel, you create a public GameObject (Slot 1, Slot 2, etc) and you set them to null. 3) When you add a card on your slot, you check if the correponsding slot is empty. if it is, you set your Card gameobject to the correponding slot, if not, you cannot drop it here.
Hope it helped :)
Your answer
Follow this Question
Related Questions
Unity UI - Fading Canvas/Panel 7 Answers
Scroll Rect Content Disappearing (Video) 1 Answer
Unity 2D not rendering images in Canvas 1 Answer
Problems with render priority in UI Canvas 2 Answers
How to get UI elements on card not to shine through? 1 Answer