public void EquipArmor(GameObject itemToEquip) { armorSlot = gameObject.transform.Find("PlayerModel").transform.Find(itemToEquip.GetComponent <IArmor>().ArmorSlot).gameObject; currentlyEquipped = armorSlot.transform.Find(itemToEquip.GetComponent <IArmor>().ArmorSlot).gameObject; if (currentlyEquipped != null) { characterStats.RemoveStatBonuses(currentlyEquipped.GetComponent <IArmor>().Stats); Destroy(currentlyEquipped); // will just be dropped or removed from slot in future } itemToEquip.transform.SetParent(armorSlot.transform, false); characterStats.AddStatBonuses(itemToEquip.GetComponent <IArmor>().Stats); Debug.Log("Equipped: " + itemToEquip); }
public void EquipWeapon(GameObject itemToEquip) { currentlyEquipped = rightHand.transform.GetChild(0).gameObject; if (currentlyEquipped != null) { characterStats.RemoveStatBonuses(currentlyEquipped.GetComponent <IWeapon>().Stats); Destroy(currentlyEquipped); // will just be dropped or removed from slot in future } currentlyEquipped = itemToEquip; currentlyEquipped.transform.SetParent(rightHand.transform, false); if (currentlyEquipped.GetComponent <IProjectileWeapon>() != null) { currentlyEquipped.GetComponent <IProjectileWeapon>().ProjectileSpawn = projectileSpawn; } equippedIWeapon = currentlyEquipped.GetComponent <IWeapon>(); characterStats.AddStatBonuses(equippedIWeapon.Stats); Debug.Log("Equipped: " + itemToEquip); }
public void Equip(ItemMeta toEquip) { if (EquippedWeapon) { stats.RemoveStatBonuses(EquippedWeapon.GetComponent <IWeapon>().Stats); Destroy(hand.transform.GetChild(0).gameObject); } EquippedWeapon = Instantiate( Resources.Load <GameObject>(Path.Combine("Weapons", toEquip.info)), hand.transform.position, hand.transform.rotation ); EquippedWeapon.GetComponent <IWeapon>().Stats = toEquip.stats; EquippedWeapon.GetComponent <IProjectileLauncher>()?.SetProjectileSpawnPoint(projectileSpawnPoint); EquippedWeapon.transform.SetParent(hand.transform); stats.AddStatBonuses(toEquip.stats); Debug.Log(EquippedWeapon); }
public void EquipItem(Equippable itemToEquip) { Debug.Log("Checking " + itemToEquip.Slot + " for existing equipment..."); if (equippedItems.Exists(x => x.Slot == itemToEquip.Slot)) { Equippable previouslyEquipped = equippedItems.Find(x => x.Slot == itemToEquip.Slot); UnEquipItem(previouslyEquipped); } Debug.Log("Equipping " + itemToEquip.name + "... "); if (baggedItems.Remove(itemToEquip)) //is the item coming from the player's own inventory? { UIEventHandler.ItemRemovedFromInventory(itemToEquip); } foreach (EquippableModel x in itemToEquip.Models) { GameObject modelAnchor = FindEquipmentSlot(transform.root.Find("PlayerModel").gameObject, (itemToEquip.Slot + x.Side)); x.transform.SetParent(modelAnchor.transform, false); x.OrientForSlot(); x.GetComponent <MeshRenderer>().enabled = true; // Check if model is projectile weapon if (x.gameObject.GetComponent <IWeapon>() != null) { playerWeaponController.equippedIWeapon = x.gameObject.GetComponent <IWeapon>(); if (x.gameObject.GetComponent <IProjectileWeapon>() != null) { Debug.Log(x.gameObject + " is a projectile weapon."); x.gameObject.GetComponent <IProjectileWeapon>().ProjectileSpawn = playerWeaponController.projectileSpawn; Debug.Log(x + "'s ProjectileSpawn is set to " + playerWeaponController.projectileSpawn + "."); } } } equippedItems.Add(itemToEquip); UIEventHandler.ItemEquipped(itemToEquip); characterStats.AddStatBonuses(itemToEquip.Stats); Debug.Log("Equipped: " + itemToEquip); }