public void DropItem(int index, bool removeFromInventory = true) { ItemEntry itemEntry = this[index]; if (!itemEntry.IsDroppable) { return; } ItemPickup pickup = ItemPickup.CreateFromItemEntry(itemEntry); Vector2 dropLocation = new Vector2( this.transform.position.x + UnityEngine.Random.Range(-this.dropOffsetRange.x, this.dropOffsetRange.x), this.transform.position.y + UnityEngine.Random.Range(-this.dropOffsetRange.y, this.dropOffsetRange.y) ); pickup.transform.position = dropLocation; if (removeFromInventory) { if (this.onItemRemoval != null) { this.onItemRemoval.Invoke(itemEntry); } this.items.RemoveAt(index); } }
public void DropItemYield() { if (this.IsReadyForHarvest) { Collider2D collider = GetComponent <Collider2D>(); foreach (ItemEntry yieldEntry in this.itemYield) { ItemPickup yield = ItemPickup.CreateFromItemEntry(yieldEntry); Vector3 dropOffset = new Vector3( UnityEngine.Random.Range(-0.5f, 0.5f), UnityEngine.Random.Range(0, 0.5f), 0); yield.transform.position = collider.bounds.max + dropOffset; } } this.cropBlock.Crop = null; this.cropBlock.Unwater(); PoolManager.Despawn(this.gameObject); }