![]() ![]() Doing this will eliminate the need to continuously update text in Update call. CharacterUI will listen to this event so that it can change the UI when the player takes damage. Let's add an onplayerDamaged event in CharacterStats so that the player can get notified when their character takes damage. These events can be used to detect when the state of the game is changed. ![]() Public class CharacterStats: ScriptableObject Multiple Classes Referencing the Same Asset Game EventsĮvents can be invoked from scriptable assets and listened to by other classes that reference them. We will be able to create this object from there creating asset menu shows scriptable object in editor menu. Incoming damage will be decreased by armor amount before decreasing health. Also, we will be adding a Damage method so that health can be decreased. It consists of the health, name and armor attributes. It will be used to store the status of a character. ![]() In this example, we will create a CharacterStats class to demonstrate the creation and use of a scriptable object. It is also helpful to create a CreateAssetMenu header from the editor menu. To make a scriptable object, we must create a class that inherits from the ScriptableObject class. Scriptable object assets can be created and stored like other assets such as images, materials, etc. Values are retained between edit and play mode. They are used as a container to store values.Ī scriptable object exists even when the game is stopped and persists between play modes. In Unity, while MonoBehaviour objects are stored in memory and exist only while playing the game Scriptable Objects exist in the project itself and are stored in serialised form. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |