//Kill the destructible public void Kill() { if (!dead) { dead = true; foreach (Collider collide in colliders) { collide.enabled = false; } //Loot foreach (CraftData item in loots) { float radius = Random.Range(0.5f, 1f); float angle = Random.Range(0f, 360f) * Mathf.Rad2Deg; Vector3 pos = transform.position + new Vector3(Mathf.Cos(angle), 0f, Mathf.Sin(angle)) * radius; if (item is ItemData) { Item.Create((ItemData)item, pos, 1); } if (item is ConstructionData) { Construction construct = Construction.Create((ConstructionData)item, pos); construct.FinishContruction(); } } if (!was_built) { PlayerData.Get().RemoveObject(GetUID()); } if (onDeath != null) { onDeath.Invoke(); } //FX if (death_fx != null) { Instantiate(death_fx, transform.position, Quaternion.identity); } TheAudio.Get().PlaySFX("destruct", death_sound); select.Destroy(destroy_delay); } }
//Use an item in your inventory and build it on the map public void BuildItem(int slot, Vector3 pos) { InventoryItemData invdata = PlayerData.Get().GetItemSlot(slot); ItemData idata = ItemData.Get(invdata.item_id); if (idata != null) { ConstructionData construct = idata.construction_data; if (construct != null) { PlayerData.Get().RemoveItemAt(slot, 1); Construction.Create(construct, pos); TheUI.Get().CancelSelection(); } } }