![]() Let the game designer now rejoice in balancing the game economy.įurthermore, other mechanisms, such as item drops from monsters or looting treasure chests, benefit just the same. The change is immediately reflected in any entity that refers to it. Every merchant holds a list of the ItemScriptableObjects it sells.Īny discounts or increases in the prices of an item are now done to the item itself. Getting back to the problem we discussed previously with detaching the ItemStructs from the elements in the game, a simple solution now is to replace ItemStructs with the ItemScriptableObject. Public class ItemScriptableObject : ScriptableObjectĪs you saw in the example above, to increase the efficiency of creating instances of a scriptable object, we can use the CreateAssetMenuAttribute to add an editor menu that generates files of that type. Moreover, they are as easy to create as regular mono behavior scripts: They can have their methods and member variables, as well as benefit from using Attributes. Scriptable objects do not inherit from MonoBehavior, the default class for Unity scripts, but they do hold some analogous behaviors and can be used in a similar fashion.įor instance, they have their Awake call, as well as OnEnable and OnDisable. They exist on their own and any entity that uses them uses a reference. Thus, we can create them without adding them to an object in our scene or a prefab. ![]() Scriptable objects are data-holding objects in Unity that do not need to be attached to game objects. Gladly, Unity offers an easy way of doing that: scriptable objects. Thus, any change made to the ItemStruct will immediately affect those who refer to it. It should be clear that the solution we are looking for revolves around detaching the ItemStruct from the merchants (and other mechanisms) and letting each one of them use a reference to it. ![]() Defeating enemies yields loot, such as potions. Applause from me if you are already using prefabs and prefab variants, but they all still need updating.īuying is one of the difficulties with programming these items, but consider that the game also has combat. Since the ItemStructs are not connected to each other, every instance of every merchant that sells them needs to be updated. If you raised one eyebrow already, prepare to raise the other, because there is a very high chance that your game designer will, at some point, try to balance the game and give a discount to all low-level potions. If we stick to the ItemStruct approach, it is probably the case now that the different instances of the merchants now have copies of the same ItemStructs. For the sake of supporting slower players, the more advanced areas in the game have merchants still selling starting potions that cost less than their higher-level alternatives. One of them, in the starting area, is supposed to sell low-level potions and weak temporary buffs. However, your merchant system allows for different merchants across the game world. The serializable structs provide an easy way of making changes via the Inspector, while also using the advantages of being a struct in C# such as being more adequate for smaller data aggregation compared to classes, and for having value semantics. This approach is actually quite versatile, and for many simple systems, it is certainly the easiest and more stable way to go. The code and inspector for such a system can be seen below: ![]() Thus, via the inspector, the game designer can input each one of these items manually while leaving you to program the other systems for the game. Then, you would add a List of ItemStruct in the merchant. I believe the initial attempt to tackle this system is to use a serializable struct that encapsulates the items’ properties. Additional advantages of scriptable objects.In this article, we’re going to be exploring fast prototyping in Unity and how you can use scriptable objects effectively in your game development. As the lead programmer, you need to decide where to store each one of these items in your system, so where would you? The game designer in your team already wrote a 100-page document on various items with an entire chapter dedicated to the multiple potion types. Consider that you are developing a merchant system for your game in Unity, where the merchant sells a list of items with a different name, price, description, and image. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |