public void DropItems() { //Calculate and drop possible items. if (this.possibleItems.Length == 0) { goto dropDefiniteItems; } int itemChance = Random.Range(0, maxPossibleChance); List <GroundedItem> possibleItems = new List <GroundedItem>(); foreach (GroundedItem item in this.possibleItems) { if (item.DropChance > itemChance) { possibleItems.Add(item); } } int possibleItemCount = Random.Range(minPossibleItemsCount, maxPossibleItemsCount); for (int i = 0; i < possibleItemCount; i++) { GroundedItem randomPossibleItem = possibleItems[Random.Range(0, possibleItems.Count)]; Instantiate(randomPossibleItem, transformCache.position, randomPossibleItem.TransformCache.rotation); } dropDefiniteItems: //Drop definite items. if (definiteItems.Length == 0) { return; } int definiteItemCount = Random.Range(minDefiniteItemsCount, maxDefiniteItemsCount); for (int i = 0; i < definiteItemCount; i++) { GroundedItem randomDefiniteItem = definiteItems[Random.Range(0, definiteItems.Length)]; Instantiate(randomDefiniteItem, transformCache.position, randomDefiniteItem.TransformCache.rotation); } }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("WinItem")) { PlayerCarriedItemController.CarriedItemCollected = true; Destroy(collision.gameObject); return; } GroundedItem groundedItem = collision.gameObject.GetComponent <GroundedItem>(); if (groundedItem != null) { if (groundedItem.ItemData.type == 0) // If collected item is a weapon { playerInventoryManager.AddWeapon(ItemConverter.ToInventoryWeapon(groundedItem)); } else { playerInventoryManager.AddItem(ItemConverter.ToInventoryItem(groundedItem, true)); } } }