Esempio n. 1
0
 public static void LootUnit(CombatUnit unit)
 {
     if (prefab == null)
     {
         prefab = Resources.Load <GameObject>("Prefabs/ItemHolder");
     }
     if (unit.lootOnDeath != null)
     {
         foreach (LootTableEntry e in unit.lootOnDeath.entries)
         {
             if (UnityEngine.Random.value < e.probability)
             {
                 GameObject   go = Instantiate(prefab, unit.transform.position + Vector3.up, Quaternion.identity);
                 PickableItem pi = go.GetComponent <PickableItem>();
                 pi.item  = e.item;
                 pi.count = UnityEngine.Random.Range(e.minCount, e.maxCount);
                 pi.InitVisibility(); // update mesh and material
                 float   forceIntensity = UnityEngine.Random.Range(100, 500);
                 Vector3 forceDirection = Quaternion.Euler(UnityEngine.Random.Range(0, 45), UnityEngine.Random.Range(0, 360), 0) * Vector3.forward;
                 go.GetComponent <Rigidbody>().AddForce(forceDirection * forceIntensity);
             }
         }
     }
 }