I want to make a weapon-equip system and here is my try:
public Item currentWeapon;
public Item.ItemMunitionType munitionType;
public Transform playerHand;
public Transform equippedeItem;
public float reloadTime;
public float fireRate;
public float projectileSpeed;
public int range;
public int damage;
public int roundsPerBurst;
public bool canBurst;
public bool fullAuto;
if(Input.GetKeyDown("2"))
{
currentWeapon = inventoryScript.equippedPrimary;
equippedeItem = currentWeapon.itemTransform;
projectileSpeed = currentWeapon.itemProjectileSpeed;
range = currentWeapon.itemRange;
fireRate = currentWeapon.itemFireRate;
reloadTime = currentWeapon.itemReloadeTime;
damage = currentWeapon.itemDamage;
roundsPerBurst = currentWeapon.itemRoundsPerBurst;
canBurst = currentWeapon.itemCanBurst;
fullAuto = currentWeapon.itemFullAuto;
munitionType = currentWeapon.itemMunitionType;
equippedTransform (equippedeItem);
}
}
private void equippedTransform (Transform transform)
{
Transform selectedItem = Instantiate(transform, playerHand.position, Quaternion.identity) as Transform;
selectedItem.parent = playerHand;
selectedItem.localPosition = Vector3.zero;
selectedItem.localRotation = Quaternion.identity;
}
Of course the “If(Input.GetKeyDown(“2”))” is in the update void. The problem is that the Transform won’t show up.
Item is a class I wrote but it’s not necessary to know for that.