Hi there!
I wanted to get the modifervalues of an instantiated object (a clone) as an equipment.
The clone runs several stages and works by showing the random generated modifiervalues on the UI, but the values of the clones aren’t adopted to the actual modifiers for damage, etc…
The only values that are adopted are the original values of the prefab.
This is where an random Item is dropped and is given random modifiervalues:
public void ItemDrop()
{
int itemNumber;
playerLvl = (int)playerLevel.charLevel.GetValue();
int randomLevel = (int)Random.Range(1, playerLvl);
if (randomLevel < 3)
{
itemNumber = Random.Range(0, itemList.Count);
Debug.Log("you got " + itemList[itemNumber] + " +" + playerLvl);
var clone = Instantiate(itemList[itemNumber]) as Equipment;
for (int i = 0; i < clone.modifiers.Length; i++)
{
if (clone.modifiers *> 0)*
clone.modifiers += (Random.Range(-10, 7) + playerLvl);
}
Inventory.instance.Add(clone);
droppedItem = clone;
}
This is where an UI shows up, when a certain button is pressed, and the clone is declared as an Equipment-object, that goes to the next methods. Even after that, there is no Problem with the UI and the correct values shown. The focus is on the beginning of the InspectItem-method and the Use-method at the very end.
public class Equipment : Items
{
public static Equipment instance;
public CompareButton compareWindow;
public EquipmentSlot equipSlot;
public int damageModifier;
public float attSpeedModifier;
public int fireDamageModifier;
public int iceDamageModifier;
public int lightningDamageModifier;
public int armorModifier;
public int fireResistenceModifier;
public int iceResistenceModifier;
public int lightningResistenceModifier;
public int movementSpeedModifier;
public float[] modifiers;
private void Awake()
{
instance = this;
modifiers = new float[] { damageModifier, attSpeedModifier, fireDamageModifier, iceDamageModifier, lightningDamageModifier, armorModifier, fireResistenceModifier, iceResistenceModifier, lightningResistenceModifier, movementSpeedModifier };
}
public override void InspectItem()
{
compareWindow = CompareButton.instance;
base.InspectItem();
compareWindow.InspectItem();
compareWindow.chosenIcon.sprite = icon;
compareWindow.chosenEquip = this;
compareWindow.ShowChosenStats(this);
compareWindow.equippedIcon.enabled = false;
compareWindow.chosenEquip.modifiers = ItemListing.instance.droppedItem.modifiers;
// if-conditions aside from this
}
public void Use()
{
EquipmentManager.instance.Equip(compareWindow.chosenEquip);
RemoveFromInventory();
}
The problem begins here, where only the values of the original prefab are transfered and shown in another UI:
void OnEquipmentChanged(Equipment newItem, Equipment oldItem)
{
if (newItem != null)
{
damage.AddModfier(newItem.damageModifier);
attSpeed.AddModfier(newItem.attSpeedModifier);
fireDamage.AddModfier(newItem.fireDamageModifier);
iceDamage.AddModfier(newItem.fireDamageModifier);
lightningDamage.AddModfier(newItem.lightningDamageModifier);
armor.AddModfier(newItem.armorModifier);
fireResistence.AddModfier(newItem.fireResistenceModifier);
iceResistence.AddModfier(newItem.iceResistenceModifier);
lightningResistence.AddModfier(newItem.lightningResistenceModifier);
movementSpeed.AddModfier(newItem.movementSpeedModifier);
}
if (oldItem != null)
{
damage.RemoveModfier(oldItem.damageModifier);
attSpeed.RemoveModfier(oldItem.attSpeedModifier);
fireDamage.RemoveModfier(oldItem.fireDamageModifier);
iceDamage.RemoveModfier(oldItem.fireDamageModifier);
lightningDamage.RemoveModfier(oldItem.lightningDamageModifier);
armor.RemoveModfier(oldItem.armorModifier);
fireResistence.RemoveModfier(oldItem.fireResistenceModifier);
iceResistence.RemoveModfier(oldItem.iceResistenceModifier);
lightningResistence.RemoveModfier(oldItem.lightningResistenceModifier);
movementSpeed.RemoveModfier(newItem.movementSpeedModifier);
}
}
I tried to declare the clone many times to different variables and let them return, etc. and tried to declare newItem in the OnEquipmentChanged-method to the Equipment.instance, but no matter, how or what I do, the stats of the clone won’t get taken over to the OnEquipmentChanged-method
At least, that’s what i suppose the problem is…
How do I get the modifiers of the clone and not the original in OnEquipmentChanged-method?