public void Equip(GameObject target) { GameObject equipmentGraphic = null; BaseStats baseStats = target.GetComponent <BaseStats>(); bool isMale = baseStats.IsMale(); string graphicName = isMale ? maleGraphicGameObjectName : femaleGraphicGameObjectName; if (this.itemType == ItemEnum.WEAPON) { defaultAnimatorOverrideController = target.GetComponent <Animator>().runtimeAnimatorController; target.GetComponent <CharacterEquipmentSlot>().EquipOnSlot(bodyPart, this); target.GetComponent <WeaponManager>().weaponSlots[0].EquipWeapon(this as ScriptableWeapon); // Instantiate weapon graphic here // Hardcode for right hand for now // instance = Instantiate(this.weaponPrefab, target.GetComponent<WeaponManager>().weaponSlots[0].gameObject.transform); target.GetComponent <Animator>().runtimeAnimatorController = this.animatorOverrideController as RuntimeAnimatorController; return; } foreach (Transform t in target.GetComponentsInChildren <Transform>(true)) { if (t.gameObject.name == graphicName) { equipmentGraphic = t.gameObject; break; } } if (equipmentGraphic == null) { return; } equipmentGraphic.SetActive(true); CharacterGraphic charGraphic = target.GetComponent <CharacterGraphic>(); ToggleBodyPart(charGraphic, bodyPart, false); target.GetComponent <CharacterEquipmentSlot>().EquipOnSlot(bodyPart, this); }
public void Unequip(GameObject target) { GameObject equipmentGraphic = null; BaseStats baseStats = target.GetComponent <BaseStats>(); bool isMale = baseStats.IsMale(); string graphicName = isMale ? maleGraphicGameObjectName : femaleGraphicGameObjectName; if (this.itemType == ItemEnum.WEAPON) { target.GetComponent <CharacterEquipmentSlot>().EquipOnSlot(bodyPart, null); target.GetComponent <Animator>().runtimeAnimatorController = defaultAnimatorOverrideController as RuntimeAnimatorController; target.GetComponent <WeaponManager>().weaponSlots[0].UnequipWeapon(); Destroy(instance); return; } foreach (Transform t in target.GetComponentsInChildren <Transform>(true)) { if (t.gameObject.name == graphicName) { equipmentGraphic = t.gameObject; break; } } equipmentGraphic.SetActive(false); CharacterGraphic charGraphic = target.GetComponent <CharacterGraphic>(); ToggleBodyPart(charGraphic, bodyPart, true); target.GetComponent <CharacterEquipmentSlot>().EquipOnSlot(bodyPart, null); }