Hello people,
I am trying to have equipments on my game that can be created several times
with the scriptable objects, two equipments will have the same information,
if this informations changes for one copy, then the other copy of the specific equipment happen to change too.
I know this is the behaviour of the scriptable objects, but what i need is like having, for example, two swords of the same scriptable object with diferent actual durability.
actualy, this is possible to do with unity?
below i am trying to create a second class called Durability on the same script,
but i am struggling to get this information after, someone can help?
SCRIPT item.cs:
using UnityEngine;
/* The base item class. All items should derive from this. */
[CreateAssetMenu(fileName = āNew Itemā, menuName = āInventory/Itemā)]
public class Item : ScriptableObject
{
new public string name = āNew Itemā; // Name of the item
public Sprite icon = null; // Item icon
public bool showInInventory = true;
public int maxqtd;
public int qtd;
public int uses;
public float durMax;
public float currentDur;
public bool isBroken;
public bool isConsumable;
public Durability newDurability()
{
Durability durability = new Durability(this);
return durability;
}
// Called when the item is pressed in the inventory
public virtual void Use()
{
// Use the item
// Something may happen
}
// Call this method to remove the item from inventory
public void RemoveFromInventory()
{
Inventory.instance.Remove(this, 0);
}
}
[System.Serializable]
public class Durability
{
public float durMax;
public float currentDur;
public bool isBroken;
public Durability(Item item)
{
durMax = item.durMax;
currentDur = item.currentDur;
isBroken = item.isBroken;
}
public void setDurability(float durMaxUP, float currentDurUP)
{
durMax = durMaxUP;
currentDur = currentDurUP;
if (currentDur <= 0)
{
isBroken = true;
}
else
{
isBroken = false;
}
}
public float getCurrentDurability()
{
return currentDur;
}
public float getmaxDurability()
{
return durMax;
}
public bool getIsBroken()
{
return isBroken;
}
}