/// <summary> /// Drop this item to the ground from the player's inventory. /// Creates a corresponding world item instance near the player's position and /// removes the corresponding instance from the player's inventory. /// </summary> public void Drop() { //Creates a corresponding world item instance near the player's position GameObject droppedItem = (GameObject)GameObject.Instantiate(EmptyItem, PlayerStateManager.Instance.transform.position, EmptyItem.transform.rotation); //Get reference to the dropped item's script WorldItemScript itemScript = droppedItem.GetComponent <WorldItemScript>(); //Initialize fields for dropped item itemScript.InitItem( ThisItem.ID, ThisItem.ItemImage, ThisItem.ItemName, ThisItem.PickupText, ThisItem.PickupText, ThisItem.ItemScale, ThisItem.ItemColor ); //Trigger menu to shift or close //Offset the item from the player's position so they don't overlap Sprite iSprite = PlayerController._instance.gameObject.GetComponent <SpriteRenderer>().sprite; droppedItem.transform.position = new Vector3(droppedItem.transform.position.x + (iSprite.bounds.extents.x * 2.0f), droppedItem.transform.position.y); //Remove item from inventory PlayerStateManager.Instance.RemoveFromInventory(this.ThisItem); }
/// <summary> /// Adds a item from the game world to the inventory. /// Converts the item from "worldItem" to "inventoryItem" in the process. /// </summary> /// <param name="item">A World Item script instance.</param> public void AddToInventory(WorldItemScript item, bool fromDialogue) { if (item != null) { //If item being added from dialogue then eschew deleting world ui elements etc if (fromDialogue) { PlayerInventory.AddItem(item.thisItem); } else { //TODO:Figure out how to make a deep copy of item to add PlayerInventory.AddItem(item.thisItem); //Remove the collected item from the game world item.GetCollected(); } } else { Debug.LogError("NULL item passed to AddToInventory!"); } }
void Start() { GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("HUDElement"); for (int i = 0; i < gameObjects.Length; i++) { if (gameObjects[i].name.Equals("HUD")) { GameObject HUDElement = gameObjects[i]; for (int j = 0; j < HUDElement.transform.childCount; j++) { if (HUDElement.transform.GetChild(j).name.Equals("ItemDesc")) { ItemDisplay = HUDElement.transform.GetChild(j).gameObject; itemName = ItemDisplay.transform.GetChild(1).GetComponent <Text>(); description = ItemDisplay.transform.GetChild(2).GetComponent <Text>(); stats = ItemDisplay.transform.GetChild(3).GetComponent <Text>(); } } } } line = GetComponentInChildren <cakeslice.Outline>(); WIScript = this.transform.GetComponent <WorldItemScript>(); ItemDisplay.SetActive(false); }
/// <summary> /// Copy this instance. /// </summary> public WorldItemScript Copy() { WorldItemScript newItem = (WorldItemScript)this.MemberwiseClone(); return(newItem); }