Beispiel #1
0
        // ===================================================================================
        // SPAWNING
        // ===================================================================================


        // -------------------------------------------------------------------------------
        // SpawnItem
        // -------------------------------------------------------------------------------
        public static void SpawnItem(ItemDropProbability tmpl, float probability, Vector3 position, GameObject dropPrefab)
        {
            if (tmpl != null && Random.value >= probability)
            {
                position.x += Random.Range(-1.0f, 1.0f);
                position.z += Random.Range(-1.0f, 1.0f);
                LootDrop drop = ((GameObject)GameObject.Instantiate(dropPrefab, position, Quaternion.identity)).GetComponent <LootDrop>();
                drop.item = tmpl;
            }
        }
Beispiel #2
0
        // -----------------------------------------------------------------------------------
        // DropItem
        // We require a dropItem function here as Instantiate is for MonoBehaviour only
        // -----------------------------------------------------------------------------------
        public void DropItem(Item item)
        {
            LootDrop drop = ((GameObject)Instantiate(dropPrefab, transform.position, Quaternion.identity)).GetComponent <LootDrop>();

            drop.transform.Translate(0, -(moveController.height / 2 + 0.08f), 0);             // 0.08 - Skin Width
            drop.transform.Translate(transform.forward * 0.5f);

            drop.item.template          = item.template;
            drop.item.defaultDurability = 1.0f;
            drop.item.defaultCharges    = 1.0f;
            drop.durability             = item.durability;
            drop.charges = item.charges;
        }
Beispiel #3
0
 // -------------------------------------------------------------------------------
 // SpawnItems
 // -------------------------------------------------------------------------------
 public static void SpawnItems(ItemDropProbability[] tmpls, Vector3 position, GameObject dropPrefab)
 {
     if (tmpls.Length <= 0)
     {
         return;
     }
     foreach (ItemDrop tmpl in tmpls)
     {
         if (tmpl != null && Random.value >= tmpl.template.rarity)
         {
             position.x += Random.Range(-1.0f, 1.0f);
             position.z += Random.Range(-1.0f, 1.0f);
             LootDrop drop = ((GameObject)GameObject.Instantiate(dropPrefab, position, Quaternion.identity)).GetComponent <LootDrop>();
             drop.item = tmpl;
         }
     }
 }