using System.Collections; using System.Collections.Generic; using UnityEngine; using KairoEngine.Core; using KairoEngine.Inventory; namespace KairoEngine.CharacterSystem { public class DropItemAction : IAction { ItemContainer itemContainer; // Reference to the character that will move ItemRef itemRef; public DropItemAction(ItemContainer itemContainer, ItemRef itemRef) { this.itemContainer = itemContainer; this.itemRef = itemRef; } public void Start() { itemContainer.RemoveItem(itemRef); Vector3 pos = itemContainer.transform.position; pos.y += 1.5f; pos.x += Random.Range(-1, 1); pos.z += Random.Range(-1, 1); GameObject obj = GameObject.Instantiate(itemRef.item.prefab, pos, itemContainer.transform.rotation); WorldItem worldItem = obj.GetComponent(); worldItem.itemName = itemRef.item.title; worldItem.quantity = itemRef.quantity; worldItem.lastUsed = itemRef.lastUsed; SerializerWorldItem serializer = obj.GetComponent(); serializer.loadedFromData = true; if(itemRef.item.category == ItemType.firearm) { ItemFirearmRef firearmRef = (ItemFirearmRef)itemRef; worldItem.itemAmmoName = firearmRef.ammoType.title; worldItem.ammoQuantity = firearmRef.ammo; } CharacterController character = itemContainer.GetComponent(); if(character !=null) { if(character.GetEquipedItem() == itemRef) { GameObject.Destroy(character.GetEquipedGameObject()); character.SetEquipedItem(null); character.SetEquipedGameObject(null); character.animator.SetInteger("Mode", 0); } } } public void Update() { } public void End() { } public bool IsDone() { return true; } } }