Hi, this is my first steps with Unity and scripting, i am doing a deck builder game like Star Realms board game, i have done some scripts easy to learn with some tutorials, but i can,t get back int values from cards to stock his value.
i have a Scriptable Object named “Card”, other script for display in Unity the card named “Card Display”; in “Card” there are an “int” variable named “CardCost”, i call this in “Card Display” too, “Card Display” take randomly the data cards from a database through another script and all finish in a prefab working fine.
I want go adding “CardCost” attached to the card to a summation when they are played. In my thinking i was going a create a panel, and when any card entering to this panel, this would detect the “CardCost” value, i tried with OnTransformChildrenChanged() associated to a PlayZone, Unity detect me correctly “CardCost” values to all cards, that is not the problem, but i can,t tell to Unity(i don,t know) how get “CardCost” when cards are played. I have problems too with GetComponent<> since he can,t handle int variables(or console tell me that).
I have doubts too about i have refer to “Card” or “CardDisplay”? i imagine what I must refer to “CardDisplay” since each card has is script attached to him.
Please, need some help, some advices… thanks in advance.
Work through some more tutorials on scriptable objects and just how Unity is set up. The reason:
This makes me think you’re not grasping the idea of instances and assets.
Lets say you have a Card that is a ScriptableObject.
You would use that Card class, properly decorated with [CreateAssetMenu] at the top, to make instances of that Card, each one being a file on disk that you commit to source control as with all your other project files.
By selecting each one, you can change its instance members, making each card different.
To actually USE that in game, you create a public Card TheCard; entry in your MonoBehavior, then you access it with TheCard.CardCost
Until you grasp the above relations between data bags (ScriptableObjects) and running live code (MonoBehaviours), it will be difficult to reason about what you’re trying to do.
There’s more than one tutorial on using scriptable objects for card games on YouTube, IIRC. Watch them, and start your game with simple ideas … don’t go too far in one step.
And if you haven’t seen the video on scriptable object architecture for games by Ryan Hipple, it’s very helpful.
If you’d like to use Ryan’s ideas as a base, Daniel Everland took the examples from the presentation and fleshed them out a bit to make them more ready to use as a system. You can find this in the asset store (it’s free) here:
Hi, thanks for responses!!! i learn a lot since what i ask this really. Yes, understand instance is very important. I did this and countless more things.