I’m currently working on a spell-card-based FPS and I’m a bit confused about how to update the player’s HUD in real time based on what cards he has in his hand.
The hand is currently represented by an array of ints, with each int being a different card, but I haven’t been able to find any good tutorials online about how to draw the cards to the screen in real time, and make them disappear when they are used.
This how I would approach this problem, i dont know the specifics of your game so some of it is speculation:
Create a texture containing all cards in a grid
I would import this to unity as a sprite and slice it up evenly so that each card is an individual sprite
I would create a Unity UI image component that I can instantiate in realtime and change the source sprite to the correct card.
I would create a new script that manages instantiating a new Image when a new card is added. Animating its RectTransform to transition it on screen. If there is a small max number of cards on screen perhaps this animation is done with the Animation system per slot or i would animate it in code with a position offset for each card. It would also transition cards offscreen and destroy them once used.
Your component that holds the array of cards would need to update this script with any changes to the hand. This can be done with a direct reference or using events.
I recommend watching some videos on the unity UI if you are not familiar:
If youre not a beginner to scripting UnityEvents may prove useful in sending updates to the UI. If you are new then I would skip this: