Can someone shed a little light on why the following code isn’t working the way I want it to? I’ve written and searched, and now i’m here, admitting defeat.
Obviously it’s part of a bigger document, but I’ve pinpointed the problem to the For Loop. I can post the rest of the code on request.
All i’m looking to do search through the inventory and check if the sprite already exists and if it does - increase it by 1. The rest of the function works, but the “var item” only holds on to the first inventory child (which is an item slot). It does increase that slot number by the correct amount of items i’ve grabbed.
So I want the loop to check if i already have the object in my inventory by matching anything (name, sprite, w/e…i’ve chosen name at the moment) and then increase it by one.
else if (slotCount > 0 && !isSprite) {
for (var item : Transform in inventory.transform) {
if (item.gameObject.name == col.gameObject.name) {
if (!isSprite && (tag == “Consumable” || tag == “Resource” )) {
var c : String = item.transform.Find(“Text”).GetComponent(Text).text;
var tCount : int = System.Int32.Parse(c) + 1;
item.transform.Find(“Text”).GetComponent(Text).text = “” + tCount;
Destroy(col.gameObject, 0.4);
isSprite = true;
return;
}
}
Help me and forever be my master.