Journal 135 — Unity App Development, Interactive Map Info Cards with Scriptable Objects
Objective: To create a general info card that goes with an interactive map, and then apply Scriptable Objects
In the last article, I set up the main menu screen and a map screen. In this article, I will lay out a general animal info card, and then set up scriptable objects to fill in the info for other animals.
First, I set up a new info card layout with a background, title, descriptions, image, logo, and a close button.
We can set up a CardView script that will be used to swap out the text and image in each card.
Now, we are ready for Scriptable Objects. These are just data containers that we will add the text and image info to swap out.
Note the Scriptable Object does not inherit from Monobehaviour so it is not attached to a game object. Also note the CreateAssetMenu instructions. This will add a new create item in the Asset menu, as you can see below.
Now, here are all the animal cards filled out, ready for the next step.
We’ll create an array to store all the animal cards for reference.
I will make a new function that will reference the card index for each card (Elements 0 through 5), and I can set that cardNumber when the buttons are clicked on the map.
Now that we have assigned each DisplayCard index to the right button, we can update the card script to assign the text and image based on that card index.
We need to also remember to update the Close Button on the animal card, in order to set the card inactive so we can return to the map view. We also need to add another On Click () event to set the animal card active to view the card information.
Finally, let’s see this in action.
Thank you for your time!