Okay, all this exists within the context of a card game, where your cards are determined by your worn equipment/weapons. I have the issue below with both how Im trying to work with my class and class, both having bad interactions in different ways.
DESIRED OUTCOME: I use resources.load (I know this is slow, thats fine) to create a reference to a prefab which includes with has all the variables set how I want for that object. [code snippet #1 below, using equipment]. Then, when I need to show that object to the player I instantiate a clone of it [code snippet 2 below, + bringing up the inventory screen] . With Equipment specifically, I want to be able to “dual wield” weapons, which means I might have 2 weapons that are the same. (or two fists for unarmed in the snippets) THEN, when I equip a new item (say a shortsword) snippet 2 removes all cards associated with the item that was there before.
THE ISSUE WITH : When changeItem() (snippet 2) checks to see if the cards source item (which is declared before adding the cards to the deck) it cannot differentiate between the 2 equipments if they have the same base prefab. SO in this scenario, both unarmed fist slots add 5 cards for a total of 10. Then I equip a sword which should remove the 5 cards associated with whichever hand I equipped it to, and replace them with 5 sword cards. But instead, it reads every card as from the fist being “removed” and gets rid of them all which leaves me with the 5 sword cards.
THE ISSUE WITH : Im pretty sure if I can figure out how to solve the issue with the equipment, I can solve the card issue too but here it is, Cards can be dynamically changed both during combat or in the outside overworld. But with this method of reference, If I change one card’s variable, it changes all other cards with the same base prefab. aka, if one “Punch” card gets its cost lowered to 0, every other punch card does as well. I have a workaround with this for right now, but its very ugly and not worth sharing. Please focus help on the equipment.
I do not think any other code is relevant here, but if you disagree lmk ill share all I can. Ty for any help or advice.
SNIPPET #1, in character, called if a character has nothing equipped in start()
** **GameObject toLoadMainHand = (GameObject)Resources.Load("Equipment/Fist");** **GameObject toLoadOffHand = (GameObject)Resources.Load("Equipment/Fist");** **changeItem(toLoadMainHand.GetComponent<Equipment>(), 1);** **changeItem(toLoadOffHand.GetComponent<Equipment>(), 2);** **updateInventory();** **
SNIPPET #2, also in character, called above
```csharp
**public void changeItem(Equipment item2Eqip, int slotType, bool leaveEmpty = false)
{
inventory.Add(equippedItems[slotType]); //adds to inventory before removing equipped
List<Card> toBeRemoved = new List<Card>();
foreach (Card r in deckMain.thisDeck)
{
if (r.sourceItem == equippedItems[slotType])
{
toBeRemoved.Add(r);
Debug.Log("scrubbed cards from main");
}
}
foreach (Card R in toBeRemoved)
{
deckMain.removeCard(R);
}
//code which adds the new items cards is here, which is working fine so not included
}
public void updateInventory()
{ //this is used to update the inventory screen
if (SP == null)
{
SP = FindObjectOfType<SceneParent>(); // I think this is a "blackboard", if that helps
}
if (SP.activeCharacter == this)
{
Destroy(GameObject.FindWithTag("ISMainHand").transform.GetChild(0).gameObject);
Instantiate(equippedItems[1].gameObject, GameObject.FindWithTag("ISMainHand").transform);
Destroy(GameObject.FindWithTag("ISOffHand").transform.GetChild(0).gameObject);
Instantiate(equippedItems[2].gameObject, GameObject.FindWithTag("ISOffHand").transform);
}**
```