/// <summary> /// Create a new drop for this item /// </summary> public static Entity_DroppedItem NewObj(ItemStack Item, Vector3 WorldLocation, Vector3 FlingForce) { Entity_DroppedItem baseEnt = Resources.Load <Entity_DroppedItem>("Entities/Dropped Item Prefab"); Entity_DroppedItem drop = Instantiate(baseEnt); drop.transform.position = WorldLocation; drop.mPickupCooldown = 2.0f; drop.mItem = Item; drop.GetComponent <Rigidbody>().AddForce(FlingForce); return(drop); }
void Update() { if (mPickupCooldown > 0) { mPickupCooldown -= Time.deltaTime; if (mPickupCooldown < 0) { mPickupCooldown = 0; } } bool invOpen = MenuController.Main.bIsInventoryOpen; // If different state, update visibility if (invOpen != bIsInventoryOpen) { bIsInventoryOpen = invOpen; mItemDisplay.bIsVisible = bIsInventoryOpen; } // Move cursor to mouse position if (bIsInventoryOpen) { transform.position = Input.mousePosition; Entity_Player player = Entity_Player.Main; if (Input.GetKeyDown(KeyCode.Mouse0)) { if (CurrentSlot != null) { CurrentSlot.OnPrimaryClick(this); } // Drop whole stack else { if (mCurrentItem.mType != ItemType.None) { // Throw item Entity_DroppedItem.NewObj( mCurrentItem, player.transform.position, new Vector3(200 * (player.mMovement.bIsFacingRight ? 1 : -1), 100, Random.Range(-50, 50)) ); mCurrentItem = new ItemStack(0); } } } if (Input.GetKey(KeyCode.Mouse1)) { if (mPickupCooldown == 0) { // Increase the pickup speed steadily mPickupCooldown = mPickupCooldownAmount; mPickupCooldownAmount -= 0.7f * Time.deltaTime; if (mPickupCooldownAmount < 0.005f) { mPickupCooldownAmount = 0.005f; } if (CurrentSlot != null) { CurrentSlot.OnSecondaryClick(this); } // Drop 1 item else { ItemStack item = mCurrentItem; if (item.mType != ItemType.None) { // Throw item Entity_DroppedItem.NewObj( new ItemStack(item.mItemID, 1), player.transform.position, new Vector3(200 * (player.mMovement.bIsFacingRight ? 1 : -1), 100, Random.Range(-50, 50)) ); // If empty, replace hand with nothing if (--item.mItemCount == 0) { item = new ItemStack(0); } mCurrentItem = item; } } } } else { mPickupCooldownAmount = 0.15f; } } }