9/12/2023 0 Comments Create scriptable object unitySince the Hero class is a Scriptable Object, you cannot use it directly without a game object. Let’s create a template to add in any type of hero that we need. ![]() We will try to spawn a Hero Scriptable Object by accessing it’s data. Then you can use the variable to access the public data of the Hero class.Ī demonstration of the same is done below. To access the scriptable object’s data, you need to create a variable of type Hero and then assign the Scriptable Object to it. If you just want to read the data then you can make them private and create small public functions to read the data. ![]() Whether to make them public or private will depend on your game’s design. You can add in any datatype that you want inside the script and save it. This allows us to access these variables from another script in play mode using an object of the Hero class. For Example, like the Hero class above, has name, health and damage set as public variables. Generally, while creating a Scriptable Object class, all the parameters are set to public. That’s because we need to add them to the scene. Now that we have created Heros, what’s next? By now, you should have noticed that nothing happened after creating the Heros. I am going to create two Heros, Cube and Capsule and assign them different properties. You can set the parameter based on your requirement in the inspector window and you have a Hero ready. This will create a Game Object of type Hero. This option is available because we used CreateAssetMenu reference in our script. Just go to the project window, right click>Create>ScriptableObject>Hero. Now that we have our template in form of a Scriptable Object data, let’s create some heroes. To create menu in Unity Editor, you can use the CreateAssetMenu reference. Then each Hero will have Name, Health and Damage properties.Īlso, we need to add an Asset menu option, so that we can create Heros from project window. Every hero will have a prefab that’s the model and animation. ![]() Let’s create some properties for our hero class that we created above.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |