![]() An InventoryItem instantiated as an InventoryItem cannot and will not ever be a child class. You have the right idea in mind, but the problem is in the execution. I actually do this in my own projects, using a base item and assigning random attributes. ![]() This is also occuring with the set up I have in the code you’re reviewing now… I tried doing something like the above here but it still created an instance that was linked with the base item, so any changes to the base also affected the instantiated item. When I learnt that the InventoryItem was an abstract class I removed the abstract and tried doing something like… ScriptableObject newItem = Instantiate(statItem) // This was inside the SetUpEquipableModifierItem method SpawnGenericPickup(statItem.SpawnPickup(Vector3.zero, 1)) StatItem.SetDisplayName($"Modifier Item") StatItem.SetItemID(Guid.NewGuid().ToString()) GameObject player = GameObject.FindGameObjectWithTag("Player") StatsEquipableItem SetUpEquipableModifierItem(StatsEquipableItem statItem) SpawnGenericPickup(equipableItem.SpawnPickup(Vector3.zero, 1)) SpawnGenericPickup(weapon.SpawnPickup(Vector3.zero, 1)) ĮquipableItem SetUpEquipableItem(EquipableItem equipableItem)ĮquipableItem.SetItemID(Guid.NewGuid().ToString()) ĮquipableItem.SetDisplayName("No Stats Equip") ĮquipableItem.SetDescription("Here you have an example of no stats equipped.") Weapon.SetDescription("This weapon is a sword.") SetUpWeaponLocations(weapon, out var location, out var category) Weapon.SetItemID(Guid.NewGuid().ToString()) WeaponConfig SetUpWeaponItem(WeaponConfig weapon) WeaponConfig weapon = createItem as WeaponConfig ĮquipableItem equipItem = createItem as EquipableItem Return SetUpEquipableModifierItem(statItem) StatsEquipableItem statItem = createItem as StatsEquipableItem InventoryItem CreateRandomItem(InventoryItem createItem) Int randomIndex = (0, itemLibrary.Count) ĬreateRandomItem(itemLibrary) I want to have a ‘Base’ item for each individually different item that could be obtained in my game, and then have the ‘CreateRandomItem()’ method use that Base Item and then fill in all the blanks without associating itself with the Base item at the end… so it can be re-usable to continuously create new items from the base item. What I’d like to do is be able to instantiate a new instance of that ‘Base EquipableItem’ or ‘Base StatsEquipableItem’ and have them be entirely different from the previously created item that occured. However despite that I got all of this working till this point… With this item my script will select a random name & description (appropriately), whether it’s stackable based on certain data and where it could be slotted if at all for the equipment or action bars and all other relevant things by RNG. When the dice is rolled it will elect one of these items to proceed forward with. Imagine with me for a moment: This gameObject will roll a dice via code when called. ![]() These items are not defined at all, all configurable properties are empty besides the generic pick up spawner on each item and their ItemID’s. String assetName = "Assets/c" + characterCounter + ".asset" ĪssetDatabase.After serializing this list, I created two different items and put them into this list: For readability sake → I have one asset that’s just the regular ‘EquipableItem’ and the other ‘StatsEquipableItem’ but the items themselves are named as ‘ Base EquipableItem’ & ‘ Base StatsEquipableItem’. Public Character(string _firstName, string _middleName, string _lastName, bool _isMale)įullName = string.Format("", firstName, middleName,Īnd here is the class that creates the Character using System.Collections Ĭharacter asset = ScriptableObject.CreateInstance() Public class Character : Scriptable Object I have tried to just type the values in the inspector but that did not run the methods in the Constructor. I have created a Constructor there, but I don't know how to create an instance of that ScriptableObject through the Constructor. Like GetDate,GetAge (which I am not showing here). I have a Character Scriptable Object and I have several methods in it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |