Questions in topic: "items"http://answers.unity.com/questions/topics/single/2801.html
The latest questions for the topic "items"Inventory with Upgradable Items and Varying Statshttp://answers.unity.com/questions/1643841/inventory-with-upgradable-items-and-varying-stats.html
Hello,
<br><br>
I created an inventory system following this tutorial series: https://www.youtube.com/watch?v=bTPEMt1RG3s&list=PLm7W8dbdfloj4CWX8RS5_cnDWVn1Q6u9Q&index=1
<br><br>
The problem with this tutorial, as well as all the other inventory tutorials I've been able to find, use scriptable objects as the items. This is fine for items that have stats that don't change, but for my game, the equipable items will be generated with a range of random stats (similar to Diablo) and players will also be able to upgrade these items multiple times to increase its stats. So using scriptable objects for this won't really work since the stats change.
<br><br>
I tried creating a GameObject and having a MonoBehaviour on that object for storing the current stats, etc., but I can't store that into the inventory because it wants an Item class. It also doesn't seem like a good idea to store GameObjects because then I would need to use GetComponent() on each GameObject every time I want to retrieve the item's stats. There has to be a better way to do this, but I'm having trouble finding what that is. The creator of that tutorial series hasn't been answering people's questions, so I'm not sure how he would handle this issue.
<br><br>
The design is really nice in that I can easily create multiple inventories/bank and different item types, but what I really need is something that can also store items with dynamic stats. Anyone know a good way to convert this inventory system to be able to do that? Thanks in advance.inventoryscriptableobjectinventory systemitemsmonobehaviorWed, 26 Jun 2019 20:18:46 GMTArithanDatabase error updating inventoryhttp://answers.unity.com/questions/1642656/database-error-updating-inventory-1.html
Hey guys, so im working on an inventory system as a feature for my finals and i currently have a database of consumables, along with this i also have a script called Inventory which has a struct and adds items to our inventory, up until here everything works perfectly. Ofcourse i also have an Items script which has an interface that allows them to be picked up. So essentially, i can pick up items pretty well. My problema comes when im trying to do the UI aspect of things… Im unsure of what is going on and how to fix this, but i want to. Main issue is this right here, "Cannot implicitly convert "Inventory.Items" to Items.
void UpdateUI()
{
int i = 0;
for (; i < inventory.Count ; i++)
{
//Error is here;
itemSlots[i].Items = inventory[i];
}
for(; i < itemSlots.Length; i++)
{
itemSlots[i].Items = null;
}
}
Here is my Items script:
public class Items : MonoBehaviour, IInteractable
{
[SerializeField]
string name;
[SerializeField]
Sprite icon;
TypeOfItem typeOfItem;
public enum TypeOfItem
{
CON,
WEP,
}
public TypeOfItem TypeOfItem1
{
get
{
return typeOfItem;
}
set
{
typeOfItem = value;
}
}
Inventory inv;
public Sprite Icon { get => icon; set => icon = value; }
void Start()
{
inv = Inventory.instance;
}
public void Interact()
{
inv.AddItem(name, Icon,TypeOfItem1);
Destroy(gameObject);
}
}
This right here is ItemSlot:
public class ItemSlot : MonoBehaviour
{
[SerializeField]
Image image;
[SerializeField]
private Items item;
public Items Items
{
get { return Items; }
set
{
Items = value;
if (Items == null)
{
image.enabled = false;
}
else
{
image.sprite = Items.Icon;
image.enabled = true;
}
}
}
private void OnValidate()
{
if (image == null)
{
image = GetComponent<Image>();
}
}
}
Also if it helps anyone figure out the problema, here is the adding to inventory part, i have not included the struct since and some other things such as access to database since its something i dont reckon that needs changing, but if anyone needs to have a look just let me know
public void AddItem(string name, Sprite sprite, Items.TypeOfItem type)
{
//Switch
if(consumableDB.ConsumableReturn(name) != null)
{
inventory.Add(new Item(name, sprite, 1));
UpdateUI();
Debug.Log("Added");
}
}
Its worth noting im inspiring my system on one that i saw on youtube, but i don't want to go the exact same route, i do not want to copy his code so any guidance helps. Thanks for the help/info people.c#databaseinventoryitemsdatabase handlingFri, 21 Jun 2019 19:48:21 GMTfrancisco_simoesStop item spawning on level reload if it has been collected AND player has passed checkpointhttp://answers.unity.com/questions/1628883/stop-item-spawning-on-level-reload-if-it-has-been.html
So I need any items a player has collected to respawn on death, until they pass a checkpoint. After that point, anything the player has collected before there death needs to destroy itself. Been up for about 16 hours and don't have the brain function to figure out if this is something difficult or if I'm just being dumb.
Below is my checkpoint code.
void Start()
{
thePlayer = GameObject.FindGameObjectWithTag("Player");
hudController = thePlayer.GetComponent<hudController>();
gameMaster = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{ gameMaster.lastCheckpoint = transform.position;
PlayerPrefs.SetInt("Lives", hudController.playerLives);
PlayerPrefs.SetInt("Beer", hudController.beerCount);
PlayerPrefs.SetInt("Score", hudController.playerScore);
}
}
}save dataitemscheckpointsMon, 06 May 2019 01:36:33 GMTAk0rnStrange Persistence of Memoryhttp://answers.unity.com/questions/1628612/strange-persistence-of-memory.html
public class Item : MonoBehaviour
{
public int itemQuantity;
[HideInInspector]
public int quantity;
private void Start()
{
quantity = itemQuantity;
}
public virtual void ActionKeyDown(KeyCode key, Inventory inv)
{
}
}
This is my Item class. When I run the game for the first time in the editor, it initializes with the correct quantity value (2). I use up all the of the item. Then, I quit and then run the game again. The quantity is still at 0.
Can someone please explain this strange behavior?inventory systemitemsstrangeinconsistentSun, 05 May 2019 03:41:20 GMTedthered1009Check distance between items and player not workinghttp://answers.unity.com/questions/1622546/check-distance-between-items-and-player-not-workin.html
I keep getting this error message:
"MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
GameManager.Update () (at Assets/Scripts/GameManager.cs:27)"
I am trying to only allow the player to pick up the items if they are in range with the tag "GroundItems". The issue arrises when I 'pick up' the first object, then everything breaks. This script is on my "GameManager" script. I feel like the scrip is wrong (I am very new to coding). Any help would be greatly appreciated!!!!![alt text][1]
[1]: /storage/temp/136497-screen-shot-2019-04-16-at-92118-am.pngplayerinteractionitemsMon, 15 Apr 2019 23:29:32 GMTPyr0man1acHow do I make an object with a rigidbody2D and boxcollider2D not collide with another?http://answers.unity.com/questions/1621197/how-do-i-make-an-object-with-a-rigidbody2d-and-box.html
Hi,
I am trying to make a game where the player can move through objects that are lying on the ground yet when he clicks on it with the curser it then adds it to the inventory.
The idea is that the items shoot out of a chest and then land on the ground upon opening it, so I need gravity (rigidbody2D) involved and a boxcollider2D involved (on the items) so the items don't faze through the floor (maybe I don't need this, I am very new).
I can't however, make the player (who also has a rigidbody2D and a boxcollider2D) walk through these objects, any help would be greatly appreciated.playercollision2ditemsThu, 11 Apr 2019 14:32:00 GMTPyr0man1acHow to Make an Object Pickup System?http://answers.unity.com/questions/1613373/how-to-make-an-object-pickup-system.html
So I'm trying to make a scavenger hunt based game, similar to the sections of Life is Strange where you have to find items. I want to make it so that when the player gets near an item, a button prompt to pick it up appears. Then, when picking it up, a counter on the screen goes up, with a picture of the item next to it. I want to apply this for multiple items.
How do I do this? Im stuck.user interfacecounteritemsitem pickupcollectible-game-objectsSun, 17 Mar 2019 12:31:52 GMTSolidSlishInventory System: How to detect equal items on a list for increasing amount?http://answers.unity.com/questions/1604412/inventory-system-how-to-detect-equal-items-on-a-li.html
I've this problem, i need to add an item on a slot, but i want the code to verify if the item that i'm adding already exist on the slot vector.
I have a separate list for every type of item in my inventory like this:
private List <Item> weapons;
private List <Item> armor;
private List <Item> consumables;
private List <Item> etc;
Then i have this slot vector:
Consumable_Slot[] consumable_slots;
The consumable slot is a class that holds the Item from the inventory with these values:
private Item consumable_on_slot;
private int consumable_amount;
private int consumable_max_amount;
i already can add an item on a slot, but i cant get how to stack items by just increasing the amount, i tried this code but it does not work:
for (int i = 1; i < consumables_slots.Length; i++)
{
if (i < inventory_reference.Get_Consumables_List ().Count)
{
if(consumables_slots[i-1] == null)
{
consumables_slots[i-1].Add_Consumable_To_Slot(inventory_reference.Get_Consumables_List()[i-1]);
}
else if(inventory_reference.Get_Consumable_On_List(i).Get_Item_ID() == consumables_slots[i-1].Get_Consumable_on_Slot().Get_Item_ID())
{
consumables_slots[i-1].Set_Consumable_Current_Amount();
}
else
{
consumables_slots[i].Add_Consumable_To_Slot(inventory_reference.Get_Consumables_List()[i]);
}
}
}
this is how i add the item on the slot:
public void Add_Consumable_To_Slot (Item new_consumable)
{
this.consumable_on_slot = new_consumable;
consumable_max_amount = consumable_on_slot.Get_Max_Amount ();
consumable_amount = 1;
text_amount_reference.text = consumable_amount.ToString ();
image_reference.sprite = consumable_on_slot.Get_Item_Icon ();
image_reference.enabled = true;
}inventoryinventory systemdetectitemsstackWed, 20 Feb 2019 20:55:58 GMTMrPenguinumOverride method for items in xml list?http://answers.unity.com/questions/1584514/override-method-for-items-in-xml-list.html
I built an xml list for items in my game and want to run an "OnPickup" method that is different for certain items (Picking up a magic item will put a curse on you, but picking up a normal item won't, etc.) but I don't know how to do this? Obviously, since all my items inherit from the same basic item class which has an OnPickup method to add the item to the player's inventory, I figured I should just override that method for items with unique pickup interactions, but I don't know how to signal this in my code.
Do I have to create separate lists for items with different interactions, and a unique class that inherits from the basic item class? Is there a way to override the method from the main xml list? The whole reason I switched to xml was to keep from cluttering up my files with individual scripts for every item. Please help!xmlinventory systemitemsFri, 28 Dec 2018 03:38:58 GMTChris1012PLEASE HELP! How can I add the material component from this scriptable object to a public list? My goal is to allow the player to apply materials to game objects from that list.http://answers.unity.com/questions/1579186/please-help-how-can-i-add-the-material-component-f-1.html
**//Application of materials from List to gameobjects script works!!**
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddOnClick : MonoBehaviour
{
public Material[] materials;
public RaycastHit hit;
public Ray ray;
Renderer rend;
void Start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100) && hit.collider.gameObject.tag == "Temperament")
{
Debug.Log(materials);
rend.sharedMaterial = materials[0];
}
}
}
}
**//But I can't add the material from the ScriptableObject to that list!!**
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Item", menuName = "Inventory/Item")]
public class Item : ScriptableObject
{
new public string name = "New Item";
public Sprite icon = null;
public bool isDefaultItem = false;
public Material prefab;
public List<Material> materials;
public virtual void Use()
{
Debug.Log("Using" + name);
addtoArray(prefab);
}
public void RemoveFromInventory()
{
}
void addtoArray(Material obj)
{
prefabs.Add(obj);
}
}materialinventorylistsitemsscriptable objectSun, 09 Dec 2018 16:18:27 GMTSavageX370Zelda-like inventory systemhttp://answers.unity.com/questions/1563783/zelda-like-inventory-system.html
Hi, I'm stuck at making an inventory system for my 2d platformer. I'd like it to be gamepad-optimized and something like the Zelda series inventories. I have no experience with XML parsing and I don't even know where to start in making it. Do you guys have any ideas? Someone keen on giving me some help? Thank you!2d2d-platformerinventoryinventory systemitemsThu, 18 Oct 2018 15:39:48 GMTDadohhDecorator pattern for inventory item classhttp://answers.unity.com/questions/1563345/decorator-pattern-for-inventory-item-class.html
Thinking about having items as classes that hold a list of "attributes" like how a gameobject holds component
That'd allow for varied items in terms of stats and other stuff, and less trouble regarding initializing/cloning items, also no issues with inheritance
Thing is it could cause problem when say, an Item has the same attribute twice with different values
Could be fixed by editor scripts but heh
Does this sound like a correct implementation of items? Anything I should know?c#inventoryinventory systemitemitemsWed, 17 Oct 2018 10:55:16 GMTMartinus3000Creating an Item Database.http://answers.unity.com/questions/1557730/creating-an-item-database.html
Hello,
I'm new to Unity and C#, and i'm currently working on my first project ( tons of tutorials doesn't count ! ).
I'm building up an Item Database, so I created an **Item** abstract class which is extended by **Weapons** ( also abstract and extended by different classes such as **Sword**, ... ), **Consumables**, etc.
I created an **ItemDatabase** class which is supposed to handle EVERY single item in my game, no matter if it's a weapon or a consumable, it only needs to be a child of **Item**.
So, in my **ItemDatabase** I created a List of Items ... but this is the problem :
Since **Items** is an abstract class I can't and don't want to instantiate an **Item** Object ... I want to create a weapon or a consumable.
I know I could add new methods to the **Editor**, to directly add a new item in the database, but ... items will not be sorted.
To be more explicit that's what I want to see in my inspector :
![alt text][1]
[1]: /storage/temp/125294-inspector.png
Lists can't handle more than one type, so could I use List to do that ?
Thanks a lot for your help !
NB : sorry if my english isn't that great.itemsFri, 28 Sep 2018 15:35:43 GMTCCnockaertInventory and scriptable object items - please point me in the right directionhttp://answers.unity.com/questions/1548834/inventory-and-scriptable-object-items-please-point.html
Quick question (at least, I hope it's quick):
This is my first time using scriptable objects, so I'm new to this stuff.
I have a BaseItem : ScriptableObject script.
Then I have a Weapons: BaseItem script, a QuestItems : BaseItem script, etc., all with BaseItem info and also some unique information.
Now, when populating the inventory, I've watched video upon video. I like the one presented in Unity's Adventure Game Tutorial, but it's set up for only populating the inventory list with the BaseItem. How do I get a master inventory list controller that'll add any kind of item? Do I need to go a whole different route? (If so, please point me in the right direction.)
The simplified inventory from the Adventure Game tutorial that I was trying to adapt:
(note: using C#)
public class Inventory: MonoBehaviour {
public const int numItemSlots = 4;
public Image[] itemImages = new Image[numItemSlots];
public BaseItem[] items = new BaseItem[numItemSlots];
public void AddItem(BaseItem itemToAdd)
{
for(int i = 0; i < items.Length; i++)
{
if(items[i] == null)
{
items[i] = itemToAdd;
itemImages[i].sprite = itemToAdd.sprite;
itemImages[i].enabled = true;
return;
}
}
}scriptableobjectinventory systemitemsSun, 02 Sep 2018 05:28:48 GMTMomcatAccessing a Class's Variables from within a Dictionary Elementhttp://answers.unity.com/questions/1536303/accessing-a-classs-variables-from-within-a-diction.html
I'm just learning how to use Dictionaries and am trying to make a catalogue of Recovery Items for my game. I've created a Recovery Item Class (with variables such as name, heal value, etc.) and am populating a Recovery Items Dictionary using the item names (strings) as the Key type and the Recovery Item (class) as the Value type, as shown below...
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class itemManager : MonoBehaviour {
public class RecItem {
public string name; // Name of recovery item
private int healVal; // Value item recovers health by
private bool oneOrAll; // T=Heals one player | F=Heals all players
public RecItem (string name, int healVal, bool oneOrAll) {
this.name = name;
this.healVal = healVal;
this.oneOrAll= oneOrAll;
}
}
public Dictionary<string, RecItem> recItems;
void Start () {
recItems = new Dictionary<string, RecItem>();
recItems.Add ("Potion", new RecItem("Potion", 100, true));
recItems.Add ("Omni-Potion", new RecItem("Omni-Potion", 100, false));
recItems.Add ("Elixer", new RecItem("Elixer", 500, true));
recItems.Add ("Omni-Elixer", new RecItem("Omni-Elixer", 500, false));
}
}
What I'm trying to figure out now is how to access the variables of the RecItems Class within each of the Dictionary's elements. I know that I can access a Dictionary's Element's value using the Key, like `recItems["Potion"];` But what I need is something along the lines of `recItems["Potion"].healVal; // Should return 100` or `recItems["Omni-Potion"].oneOrAll //Should return false` to obtain the values of the variables within the element's RecItems class. Hopefully that made sense -laugh- Thank you in advance :)c#inventorydictionaryitemselementsTue, 31 Jul 2018 00:44:25 GMTAlfredoAVASpawning Items from In Game Shop and Adding Items to Inventoryhttp://answers.unity.com/questions/1535514/in-game-shop-2.html
I successfully set up my shop, and it works by adding GameObjects (Items) to the Player's Inventory. Unfortunately, I have run into another issue. I am using an ItemManager to spawn prefab clones and then I add those clones to the Player's Inventory and set the world items as not active.
Is there a way to do this without using Instantiate? Or do I have to spawn an item then add it to the layer inventory? Also is setting using SetActive better than using Destroy and Instantiate every time you get rid of and add an item onto the scene?activeinstantiate prefabitemsshopSun, 29 Jul 2018 05:09:41 GMTDaUr3ScriptableObject for custom items & spells in-gamehttp://answers.unity.com/questions/1527065/scriptableobject-for-custom-items-spells-in-game.html
Hey there.
So I've got an inventory set up that stores a list of ScriptableObjects that make up all of my items, including weapons and armour, etc., as well as a "Spellbook" section for holding all of the player's spell objects. The player can equip a sword SO that references a mesh, which will be displayed on screen, but all of the damage calculation happens through the stats held within the SO.
<br>
ScriptableObjects are great for quickly creating objects inside the editor, but if I want to implement some sort of system where the player can create their own objects with custom stats, is there any way to do this with SO's?
<br>
I want the player to be able to go into a spellmaking interface, where they can select a "Fire Projectile" or "Heal Self" type and then set the variables for damage and speed inside that interface, then save all of this to a spell object that gets added to the "Spellbook" list. I guess what I'm describing is the process of making a SO through "Assets->Create" in the editor, but in the game instead. Is this possible?
<br>
This concept also extends to creating enchantments for weapons and armour as well. If the player has an Iron Sword that's the same as all the other Iron Swords (due to being created through a SO), and they want to create an enchantment that modifies the damage of that weapon, or the weight or any of the predefined stats from the SO, would this be possible?
<br>
Basically will SO's work with these ideas or will I have to go back to using prefabs with monobehaviours?
Thanks, hopefully that all made sense!c#scriptableobjectcustomizationitemsspellsMon, 09 Jul 2018 05:05:47 GMTMcVittyHow i can make a script-made button interactable?http://answers.unity.com/questions/1526611/how-i-can-make-a-list-like-inventory-system.html
I want to make an inventory system thats like a list. Like this:![alt text][1]
Now let me show you what i achieved:
![alt text][2]
Basically there are two items in my inventory right now which are shown up to players by using buttons. I can't figure a way to make these buttons work, so when they are clicked, the item gets removed and the whole inventory re-updates. Here is my simple script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemList : MonoBehaviour {
List<Item> itemList = new List<Item> ();
void Start () {
// Init
itemList.Add(new Item("Sword",50));
itemList.Add (new Item ("Potion", 10));
}
void Update()
{
}
void OnGUI() {
for (int i = 0; i < itemList.Count; i++)
{
GUI.Button (new Rect (100 , 50 * i, 100, 35), itemList [i].itemName);
}
}
}
[1]: /storage/temp/120322-maxresdefault.jpg
[2]: /storage/temp/120324-untitled.png
I also have a script in which i created that "Item" list. Thats a simple, normal list in which i define an "itemName" and an "itemWeight".
So, how i can recreate the inventory which was shown in the beginning of this thread? I don't really need such a complicated thing tho, i need to know how to make those buttons work!
Also, i need to do this inventory a scrollable list. I haven't looked into it but i will need to.listinventoryinventory systemitemitemsSat, 07 Jul 2018 18:08:15 GMTGunPointRemove item from list when clicked on?http://answers.unity.com/questions/1524804/remove-item-from-list-when-clicked-on.html
I have a list of items that show in my game as a list of buttons that can be clicked on to be removed. Right now my code isn't removing any items or buttons. I'm not sure how to get it to remove the button/item I click on. I should note, the item I am trying to remove/delete is actually a deep copy of the original item. That may be part of the issue but I'm not sure how. Here is my code:
public class ActivityScrollList : MonoBehaviour {
public void RemoveItem(Item itemToRemove, ActivityScrollList scrolllist)
{
for (int i = scrolllist.itemList.Count - 1; i >= 0; i--) {
if (scrolllist.itemList [i] == itemToRemove) {
scrolllist.itemList.RemoveAt (i);
}
}
}
private void RemoveButtons(){
while (contentPanel.childCount > 0) {
GameObject toRemove = transform.GetChild (0).gameObject;
buttonObjectPool.ReturnObject (toRemove);
}
}
public void TransferItem(Item item){
RemoveItem (item, this);
}
public class ActivityBookButton : MonoBehaviour {
public Item item;
private ActivityScrollList scrollList;
void Start () {
button.onClick.AddListener (moveButton);
}
public void moveButton()
{
scrollList.TransferItem(item);
}
}
What is the issue with my code and why isn't it removing the item from my list when I click it?buttonslistsonclickitemsremoveatTue, 03 Jul 2018 02:40:33 GMTjcfrizzBest Way to do Regular Items and Weapons/Intractable/Special Items.http://answers.unity.com/questions/1524422/best-way-to-do-regular-items-and-weaponsintractabl.html
I was just wondering if there was a good way to differentiate between a regular item and a special item in game.
To give a little more detail to what I am talking about, say you are playing a like Fortnite or PUBG. In Fortnite whenever you pickup an item such as Ammo or Building Materials, they are added to separate inventories, and in PUBG guns get their own special inventories.
Right now to determine if Items are have a special property, I just cast the pickup item as a Weapon (as Weapon extends off of Item)
public void PickupItem(Item item) {
if (item.type == ItemType.WEAPON) {
Weapon weapon = (Weapon) item;
// Do thing
}
}
I feel like this isn't the best way to do things, but that's kind of all I have right now. I am also using the type of enumeration to determine what type of interface said item is interfacing.
Basically, This question is kind of general. I am asking about the following points:
* Is there a better way to implement item pickup besides checking an enum and then casting to another more specific type?
* Should the base item class have methods that listen to input? I thought this would kind of be weird because you don't need an attack1() or attack2() method in an item like wood, but you would need them if you are making an Assault Rifle.
* Currently my base Item class extends Monobehaviour so I can easily attach it onto objects, but I feel like because of this system, the Item Inventory might be a bit less inefficient. Should I split the current Item base class into a sort of Item Monobehaviour and another Item ScriptableObject/Class?inventoryitemitemsitem pickupMon, 02 Jul 2018 06:59:20 GMTDaUr3How to only destroy the object the i am in.http://answers.unity.com/questions/1519427/how-to-only-destroy-the-object-the-i-am-in.html
I am trying to make a item drop system. I want to have the drop to drop(spawn) in a random location(which works fine by using a gameobject as the spawn point ) and be destroyed so i can drop an item. the problem is i don't know how to only destroy the item that i am standing in && when i press "e".triggerspawningitemsMon, 18 Jun 2018 19:16:54 GMTmmssyy25Inventory armor wielding proplem,How to convert from derived to basehttp://answers.unity.com/questions/1512770/inventory-armor-wielding-proplemhow-to-convert-fro.html
Hi, i have tried to do armor swapping script for my projet and got stuck with classes. any idea how to make funktion where you can input armor iten thats class is "Armor" an asiing it to variable with type "ArmorTorso". "Armor" is scriptable object and "ArmorTorso" is derived from it. Here is my code and proplems in it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour {
public List<Item> inventory;
private List<Armor> tempWieldetArmor;
public List<Armor> wieldetArmor
{
get { tempWieldetArmor = new List<Armor>();
if (armorChest != null)
tempWieldetArmor.Add(armorChest);
if (armorHead != null)
tempWieldetArmor.Add(armorHead);
if (armorLegs != null)
tempWieldetArmor.Add(armorLegs);
if (armorArms != null)
tempWieldetArmor.Add(armorArms);
return tempWieldetArmor;
}
}
public TorsoArmor armorChest;
public HeadArmor armorHead;
public LegArmor armorLegs;
public ArmArmor armorArms;
public Weapon weapon;
public Shield shield;
public int inventorySize = 20;
public bool WieldFromInventory( Armor armorToWield) // problem 1. how to refer armor correctly
{
Armor tempArmor = new Armor();
if (armorToWield == null)
return false;
if(armorToWield is TorsoArmor)
{
if (armorChest == null)
{
armorChest = armorToWield; // proplem 2, how to armorChest to armorToWield (convert type "armor" to "torsoarmor")
}
else
{
tempArmor = armorChest;
armorChest = armorToWield; // proplem 2, how to armorChest to armorToWield
RemoveFromInventory(armorToWield);
AddToInventory(tempArmor);
tempArmor = new Armor();
}
}
if (armorToWield is HeadArmor)
{
// chacge somne armor
}
if (armorToWield is LegArmor)
{
// chacge somne armor
}
if (armorToWield is ArmArmor)
{
// chacge somne armor
}
}
public bool AddToInventory(Item item)
{
if (inventory.Count >= inventorySize)
return false;
else
{
inventory.Add(item);
return true;
}
}
public bool RemoveFromInventory(Item item)
{
if (!inventory.Contains(item))
return false;
else
{
inventory.Remove(item);
return true;
}
}
}
Blockquoteclassinventoryscriptableobjectinventory systemitemsThu, 31 May 2018 11:56:48 GMTjukka-tamminencan you read json file on android ? I have a thesis and it's not going well.http://answers.unity.com/questions/1509876/can-you-read-json-file-on-android-i-have-a-thesis.html
I have these codes for my item database, it works on pc, but doesn't work on my android phone
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
using System.IO;
public class ItemDatabase : MonoBehaviour
{
private List<Weapon> WeaponDatabase = new List<Weapon>();
private List<Armor> ArmorDatabase = new List<Armor>();
private List<Potion> PotionDatabase = new List<Potion>();
private JsonData WeaponData, ArmorData, PotionData;
void Start()
{
WeaponData = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/Scripts/Weapons.json"));
ArmorData = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/Scripts/Armors.json"));
PotionData = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/Scripts/Potions.json"));
ConstructItemDatabase();
}
public Weapon FetchWeaponbyID(int id)
{
for (int i = 0; i < WeaponDatabase.Count; i++)
{
if (WeaponDatabase[i].ID == id)
{
return WeaponDatabase[i];
}
}
return null;
}
public Armor FetchArmorbyID(int id)
{
for (int i = 0; i < ArmorDatabase.Count; i++)
{
if (ArmorDatabase[i].ID == id)
{
return ArmorDatabase[i];
}
}
return null;
}
public Potion FetchPotionbyID(int id)
{
for (int i = 0; i < PotionDatabase.Count; i++)
{
if (PotionDatabase[i].ID == id)
{
return PotionDatabase[i];
}
}
return null;
}
void ConstructItemDatabase()
{
for (int x = 0; x < WeaponData.Count; x++)
{
WeaponDatabase.Add(new Weapon((int)WeaponData[x]["ID"], WeaponData[x]["ItemName"].ToString(),
(int)WeaponData[x]["Damage"], (bool)WeaponData[x]["Stackable"], (bool)WeaponData[x]["Equipable"],
WeaponData[x]["Slug"].ToString(), WeaponData[x]["Description"].ToString()));
}
for (int x = 0; x < ArmorData.Count; x++)
{
ArmorDatabase.Add(new Armor((int)ArmorData[x]["ID"], ArmorData[x]["ItemName"].ToString(),
(int)ArmorData[x]["MaxHealth"], (bool)ArmorData[x]["Stackable"], (bool)ArmorData[x]["Equipable"],
ArmorData[x]["Slug"].ToString(), ArmorData[x]["Description"].ToString()));
}
for (int x = 0; x < PotionData.Count; x++)
{
PotionDatabase.Add(new Potion((int)PotionData[x]["ID"], PotionData[x]["ItemName"].ToString(),
(int)PotionData[x]["HealAmount"], (bool)PotionData[x]["Stackable"], (bool)PotionData[x]["Equipable"],
PotionData[x]["Slug"].ToString(), PotionData[x]["Description"].ToString()));
}
}
public class Weapon
{
public int ID { get; set; }
public string ItemName { get; set; }
public int Damage { get; set; }
public bool Stackable { get; set; }
public bool Equipable { get; set; }
public string Description { get; set; }
public string Slug { get; set; }
public Sprite Sprite { get; set; }
public Weapon(int _id, string _itemName, int _damage, bool _stackable, bool _equipable, string _slug, string _description)
{
this.ID = _id;
this.ItemName = _itemName;
this.Stackable = _stackable;
this.Equipable = _equipable;
this.Damage = _damage;
this.Slug = _slug;
this.Description = _description;
this.Sprite = Resources.Load<Sprite>("Sprites/Weapons/" + this.Slug);
}
public Weapon()
{
this.ID = -1;
}
}
public class Armor
{
public int ID { get; set; }
public string ItemName { get; set; }
public int MaxHealth { get; set; }
public bool Stackable { get; set; }
public bool Equipable { get; set; }
public string Description { get; set; }
public string Slug { get; set; }
public Sprite Sprite { get; set; }
public Armor(int _id, string _itemName, int _maxhealth, bool _stackable, bool _equipable, string _slug, string _description)
{
this.ID = _id;
this.ItemName = _itemName;
this.Stackable = _stackable;
this.Equipable = _equipable;
this.MaxHealth = _maxhealth;
this.Slug = _slug;
this.Description = _description;
this.Sprite = Resources.Load<Sprite>("Sprites/Armors/" + this.Slug);
}
public Armor()
{
this.ID = -1;
}
}
public class Potion
{
public int ID { get; set; }
public string ItemName { get; set; }
public bool Stackable { get; set; }
public bool Equipable { get; set; }
public string Description { get; set; }
public string Slug { get; set; }
public int HealAmount { get; set; }
public Sprite Sprite { get; set; }
public Potion(int _id, string _itemName, int _healamount, bool _stackable, bool _equipable, string _slug, string _description)
{
this.ID = _id;
this.ItemName = _itemName;
this.Stackable = _stackable;
this.Equipable = _equipable;
this.HealAmount = _healamount;
this.Slug = _slug;
this.Description = _description;
this.Sprite = Resources.Load<Sprite>("Sprites/Potions/" + this.Slug);
}
public Potion()
{
this.ID = -1;
}
}
How can I make it better, please, I need an answer. please help me.
the images for the items in the inventory are showing correctly on my pc,
but for android its null.androidunity 5android buildjsonitemsThu, 24 May 2018 06:27:13 GMTAvatarWukongOnly want to change one item in list and not all of it's duplicates?http://answers.unity.com/questions/1503253/only-want-to-change-one-item-in-list-and-all-of-it.html
Hi guys, I have a question involving lists and object pools. I am not sure how to best go about fixing this problem.
So, I have an object pool where I create a list of items. When the game starts, these items form into a list of buttons. When a button is clicked on, the item is duplicated and sent to the other list of buttons, and the date it is added to the list is written on the button. The issue is, if I click the same button twice, then all of the times automatically change to the same value. Here are some screenshots to show what i mean:
When my first item, "Go to Work", is added to my list in game, the time displays correctly:
![alt text][1]
But, when I add another "Go to Work" button to my list, both times reset to become the same time! Here is what happens:
![alt text][2]
[1]: /storage/temp/116399-one-item.png
[2]: /storage/temp/116400-two-items.png
By the way, in the images shown, this is the list that I am adding buttons to, from another list. What I want is for the time on one to say 14:55 and the time on the other to say 14:57... but they both change to 14:57 automatically. This doesn't happen when I select a button to add that has a different name, but only when they are the same starting out.
**Here my code dealing with the object pool, items, and buttons:**
Code where the buttons are created:
[System.Serializable]
public class Item
{
public string activityName;
public Sprite icon;
public float Productivity = 1f;
public float Social = 1f;
public float Health = 1f;
public float Fun = 1f;
public string dateButtonAdded;
public string timeAdded;
public Sprite checkMark;
}
public class ActivityScrollList : MonoBehaviour {
public List<Item> itemList;
public Transform contentPanel;
public ActivityScrollList otherShop;
public SimpleObjectPool buttonObjectPool;
private void AddItem(Item itemToAdd, ActivityScrollList activityList){
activityList.itemList.Add (itemToAdd);
}
private void AddButtons()
{
for (int i = 0; i < itemList.Count; i++) {
Item item = itemList [i];
GameObject newButton = buttonObjectPool.GetObject ();
newButton.transform.SetParent (contentPanel);
ActivityBookButton activityButton = newButton.GetComponent<ActivityBookButton> ();
activityButton.Setup (item, this);
activityButton.SetupDate (item, this);
}
}
Code where items are assigned to elements of my buttons:
public class ActivityBookButton : MonoBehaviour {
public Button button;
public Text nameLabel;
public Image iconImage;
public Text prodValue;
public Text socValue;
public Text healthValue;
public Text funValue;
public Image checkMark;
public Text timeAdded;
public Item item;
private ActivityScrollList scrollList;
public void Setup(Item currentItem, ActivityScrollList currentScrolllist){
item = currentItem;
nameLabel.text = item.activityName;
iconImage.sprite = item.icon;
prodValue.text = item.Productivity.ToString ();
socValue.text = item.Social.ToString ();
healthValue.text = item.Health.ToString ();
funValue.text = item.Fun.ToString ();
checkMark.sprite = item.checkMark;
scrollList = currentScrolllist;
}
public void SetupDate(Item currentItem, ActivityScrollList currentScrolllist)
{
item = currentItem;
timeAdded.text = item.timeAdded;
scrollList = currentScrolllist;
}
Also if you want to see the code for my object pool, I just used the object pool code from the tutorial here:
https://unity3d.com/learn/tutorials/topics/user-interface-ui/scroll-view
I used the code for "SimpleObjectPool" at the bottom of the page. I know this is a lengthy post so thanks a million to anyone who even suggests any ideas, but I just was hoping for some outside opinions on how to go about this. Thanks for any help or responses in advance!uilistsduplicateitemsobject poolMon, 07 May 2018 21:39:29 GMTjcfrizzHow can I spawn an item after killing a wave of 6 enemies?,How can I spawn an item after clearing a wave of 6 enemies?http://answers.unity.com/questions/1472021/how-can-i-spawn-an-item-after-killing-a-wave-of-6.html
Hi,
I'm at my wits end with this one trying to figure out how to end this argument. I'm trying to spawn an item after the last enemy has been killed by the player and all enemies in the wave must also die to be rewarded.
I have a script of the enemy that counts an int value on this script. When it hits 6, it spawns the buff but my two main issues are; spawning just **one** prefab item and; at the last enemies location.
Here's my current code:
**public class Plane : MonoBehaviour
{
public bool waveOneKilled = false;
public int enemyOneKillCount = 0;
public GameObject powerUpPrefab;
IEnumerator WaveOneBuff()
{
yield return new WaitForSeconds(0);
Instantiate(powerUpPrefab, new Vector3(13, -6, 0), Quaternion.identity);
}
for (int i = 0; i < 1; i++)
{
if (enemyOneKillCount == 6)
{
StartCoroutine(WaveOneBuff());
}
}
}**
Any help would be greatly appreciated! :)
Thanks.spawnspawningitemitemspowerupThu, 22 Feb 2018 13:40:45 GMTHarvizlAccess to slot Itemhttp://answers.unity.com/questions/1466766/access-to-slot-item.html
I want to get the "Item id" to put in the
> (Slot1.GetChild(0).tag == "Item")
so i know what item its inside the slot and then spawn it.
if (Input.GetKeyDown (KeyCode.Alpha1))
{
if (Slot1.GetChild(0).tag == "Item")
{
axe.gameObject.SetActive (false);
}
else
{
axe.gameObject.SetActive (true);
}
}inventory systemitemsslotSat, 10 Feb 2018 11:44:15 GMTMrNunoPTloading player with item to have ?http://answers.unity.com/questions/1442493/loading-player-with-item-to-have.html
i have question difrent for this video if create loading for other scene how can you transport the player that you have with all item which has﻿![alt text][1]
[1]: /storage/temp/107371-loading-item.pngjavascriptplayerloadingitemsThu, 14 Dec 2017 11:34:43 GMTwatercatHow to load a chosen item while using LoadSceneAsynchttp://answers.unity.com/questions/1437681/how-to-load-equiped-items-on-loading-page.html
I was thinking of a game where a character can buy different items and equip them, I know that if I want to load them in the level I can use playerPrefs on Start() , but since I wanna load the scene with a loading bar , how can I load the chosen item to the scene while using LoadSceneAsync?loaditemsloadlevelasyncFri, 01 Dec 2017 21:04:23 GMTExtraFlashIs there a way to use the prefab image unity shows?http://answers.unity.com/questions/1436917/is-there-a-way-to-use-the-prefab-image-unity-shows.html
Okay so I'm working on an inventory system in my rpg game and I would like to have an image or a sprite for all the items in my game. I noticed that when you make a prefab of a game object in unity it will show a picture of said prefab in the project section of unity. Is there anyway I can use this picture in my game? Thanks :-)uiinventoryui imageitemsThu, 30 Nov 2017 01:25:26 GMTMpsteve137Picking up and object and then dropping it againhttp://answers.unity.com/questions/1435188/picking-up-and-object-and-then-dropping-it-again.html
I am trying to drop the axe at the player's feet.
public class playerController : MonoBehaviour
{
public GameObject playerObject;
public GameObject Stone_Axe_db;
public GameObject Stone_Axe;
public bool hasStoneAxe = false;
public bool axeEquipped = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.G))
{
if (axeEquipped)
{
//Create a new Stone_Axe object at the playerObject's position
Stone_Axe_db.SetActive(false);
hasStoneAxe = false;
axeEquipped = false;
}
}
}
private void OnTriggerEnter(Collider collision)
{
if (collision.gameObject.name == "Stone_Axe" )
{
Stone_Axe_db.SetActive(true);
hasStoneAxe = true;
axeEquipped = true;
//Get rid of the object
}
}
}
I tried changing active from false to true, but I think that means its just the same object going invisible and visible again? I want to delete the object when I pick it up, and then create another instance of it when I drop it. I tried using destroy() and then instantiate() but I get errors.
Can someone please help me with what I need to put where the comments are to make this work?
I am totally new to c# and Unity. TIA.itemsitem pickupSat, 25 Nov 2017 09:13:52 GMTNieuwoudt