Stats EquipableItem
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Inventories;
using RPG.Stats;
namespace RPG.EquipedInventories
{
[CreateAssetMenu(menuName = ("RPG/Inventory/Equipable Item"))]
public class StatsEquipableItem : EquipableItem, IModefierProvider
{
[SerializeField]
Modifier[] additiveModifiers;
[SerializeField]
Modifier[] percentageModifiers;
[System.Serializable]
struct Modifier
{
public Stat stat;
public float value;
}
public IEnumerable<float> GetAdditiveModifiers(Stat stat)
{
foreach (var modifier in additiveModifiers)
{
if (modifier.stat == stat)
{
yield return modifier.value;
}
}
}
public IEnumerable<float> GetPercentageModifiers(Stat stat)
{
foreach (var modifier in percentageModifiers)
{
if (modifier.stat == stat)
{
yield return modifier.value;
}
}
}
}
}
StatsEquipment
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Inventories;
using RPG.Stats;
namespace RPG.EquipedInventories
{
public class StatsEquipment : Equipment, IModefierProvider
{
IEnumerable<float> IModefierProvider.GetAdditiveModifiers(Stat stat)
{
foreach (var slot in GetAllPopulatedSlots())
{
var item = GetItemInSlot(slot) as IModefierProvider;
if (item == null) continue;
foreach (float modifier in item.GetAdditiveModifiers(stat))
{
yield return modifier;
}
}
}
IEnumerable<float> IModefierProvider.GetPercentageModifiers(Stat stat)
{
foreach (var slot in GetAllPopulatedSlots())
{
var item = GetItemInSlot(slot) as IModefierProvider;
if (item == null) continue;
foreach (float modifier in item.GetPercentageModifiers(stat))
{
yield return modifier;
}
}
}
}
}
WeaponConfig
using UnityEngine;
using RPG.Core;
using RPG.Attributes;
using RPG.Inventories;
using RPG.Stats;
using System.Collections.Generic;
namespace RPG.Combat
{
[CreateAssetMenu(fileName = "Weapon", menuName = "Weapons/Make New Weapon", order = 0)]
public class WeaponConfig : EquipableItem, IModefierProvider
{
[SerializeField] AnimatorOverrideController animatorOverride = null;
[SerializeField] Weapon equippedPrefab = null;
[SerializeField] float weaponDamage = 5f;
[SerializeField] float percentageBonus = 0;
[SerializeField] float weaponRange = 2f;
[SerializeField] bool isRightHanded = true;
[SerializeField] Projectile projectile = null;
const string weaponName = "Weapon";
public Weapon Spawn(Transform rightHand, Transform leftHand, Animator animator)
{
DestroyOldWeapon(rightHand, leftHand);
Weapon weapon = null;
if (equippedPrefab != null)
{
Transform handTransform = GetTransform(rightHand, leftHand);
weapon = Instantiate(equippedPrefab, handTransform);
weapon.gameObject.name = weaponName;
}
var overrideController = animator.runtimeAnimatorController as AnimatorOverrideController;
if (animatorOverride != null)
{
animator.runtimeAnimatorController = animatorOverride;
}
else if (overrideController != null)
{
animator.runtimeAnimatorController = overrideController.runtimeAnimatorController;
}
return weapon;
}
private void DestroyOldWeapon(Transform rightHand, Transform leftHand)
{
Transform oldWeapon = rightHand.Find(weaponName);
if (oldWeapon == null)
{
oldWeapon = leftHand.Find(weaponName);
}
if (oldWeapon == null) return;
oldWeapon.name = "DESTROYING";
Destroy(oldWeapon.gameObject);
}
private Transform GetTransform(Transform rightHand, Transform leftHand)
{
Transform handTransform;
if (isRightHanded) handTransform = rightHand;
else handTransform = leftHand;
return handTransform;
}
public bool HasProjectile()
{
return projectile != null;
}
public void LaunchProjectile(Transform rightHand, Transform leftHand, Health target, GameObject instigator, float calculatedDamage)
{
Projectile projectileInstance = Instantiate(projectile, GetTransform(rightHand, leftHand).position, Quaternion.identity);
projectileInstance.SetTarget(target, instigator, calculatedDamage);
}
public float GetDamage()
{
return weaponDamage;
}
public float GetPercentageBonus()
{
return percentageBonus;
}
public float GetRange()
{
return weaponRange;
}
public IEnumerable<float> GetAdditiveModifiers(Stat stat)
{
if (stat == Stat.Damage)
{
yield return weaponDamage;
}
}
public IEnumerable<float> GetPercentageModifiers(Stat stat)
{
if (stat == Stat.Damage)
{
yield return percentageBonus;
}
}
}
}
I hope its just a stupid mistake I did and that you could help me with that :)!
P.s Also the healthy hat won’t saved when changing scenes so I am super confused what could be wrong