Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class HUDInventory : MonoBehaviour {
- //Inventory Variables
- public int InventoryFieldSelected = 1;
- public int ActiveItem = 0;
- public int InventoryFromTop = 600;
- public int ItemToPickUp = 0;
- public int SlotToTransferPickUp = 0;
- // Slots Background Textures
- public Texture Slot1Background;
- public Texture Slot2Background;
- public Texture Slot3Background;
- public Texture Slot4Background;
- public Texture Slot5Background;
- public Texture Slot6Background;
- public Texture Slot7Background;
- public Texture Slot8Background;
- public Texture Slot9Background;
- public Texture Slot0Background;
- //Item Icons generally
- //0
- static public Texture InventoryIconEmpty;
- //1
- public Texture InventoryIconHammer;
- //2
- public Texture InventoryIconPipe;
- //Item Icon for Slot
- public Texture ItemIconSlot1 = InventoryIconEmpty;
- public Texture ItemIconSlot2;
- public Texture ItemIconSlot3;
- public Texture ItemIconSlot4;
- public Texture ItemIconSlot5;
- public Texture ItemIconSlot6;
- public Texture ItemIconSlot7;
- public Texture ItemIconSlot8;
- public Texture ItemIconSlot9;
- public Texture ItemIconSlot0;
- // What Item is in Slot?
- public int ItemInSlot1 = 0;
- public int ItemInSlot2 = 0;
- public int ItemInSlot3 = 0;
- public int ItemInSlot4 = 0;
- public int ItemInSlot5 = 0;
- public int ItemInSlot6 = 0;
- public int ItemInSlot7 = 0;
- public int ItemInSlot8 = 0;
- public int ItemInSlot9 = 0;
- public int ItemInSlot0 = 0;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- //Select Fields per Keyboard
- if(Input.GetKeyUp("1")){InventoryFieldSelected = 1;}
- if(Input.GetKeyUp("2")){InventoryFieldSelected = 2;}
- if(Input.GetKeyUp("3")){InventoryFieldSelected = 3;}
- if(Input.GetKeyUp("4")){InventoryFieldSelected = 4;}
- if(Input.GetKeyUp("5")){InventoryFieldSelected = 5;}
- if(Input.GetKeyUp("6")){InventoryFieldSelected = 6;}
- if(Input.GetKeyUp("7")){InventoryFieldSelected = 7;}
- if(Input.GetKeyUp("8")){InventoryFieldSelected = 8;}
- if(Input.GetKeyUp("9")){InventoryFieldSelected = 9;}
- if(Input.GetKeyUp("0")){InventoryFieldSelected = 0;}
- //TEST PICK UP HAMMER
- if(Input.GetKeyUp("h")){ItemToPickUp = 1; PickUpItem();}
- //Set ActiveItem
- if (InventoryFieldSelected == 1){ActiveItem = ItemInSlot1;}
- if (InventoryFieldSelected == 2){ActiveItem = ItemInSlot2;}
- if (InventoryFieldSelected == 3){ActiveItem = ItemInSlot3;}
- if (InventoryFieldSelected == 4){ActiveItem = ItemInSlot4;}
- if (InventoryFieldSelected == 5){ActiveItem = ItemInSlot5;}
- if (InventoryFieldSelected == 6){ActiveItem = ItemInSlot6;}
- if (InventoryFieldSelected == 7){ActiveItem = ItemInSlot7;}
- if (InventoryFieldSelected == 8){ActiveItem = ItemInSlot8;}
- if (InventoryFieldSelected == 9){ActiveItem = ItemInSlot9;}
- if (InventoryFieldSelected == 0){ActiveItem = ItemInSlot0;}
- //Send ActiveItem to PlayerAttack.cs
- PlayerAttack.ActiveItem = ActiveItem;
- }
- void OnGUI ()
- {
- GUI.BeginGroup(new Rect(500, InventoryFromTop, 640, 64));
- //GUI.contentColor = Color.yellow;
- //InventoryField1
- //======= first problem ====================================
- //==========================================================
- //== I want to Add the following line the all Slots ========
- //== to display an image of the Item that is in this Slot
- //== If i add this line, the whole inventory isnt displayed anymore
- //==========================================================
- //==========================================================
- //GUI.DrawTexture(new Rect(0,0,64,64), ItemIconSlot1);
- if (GUI.Button(new Rect(0, 0, 64, 64), Slot1Background))
- {InventoryFieldSelected = 1;}
- //InventoryField2
- if (GUI.Button(new Rect(64, 0, 64, 64), Slot2Background))
- {InventoryFieldSelected = 2;}
- //InventoryField3
- if (GUI.Button(new Rect(128, 0, 64, 64), Slot3Background))
- {InventoryFieldSelected = 3;}
- //InventoryField4
- if (GUI.Button(new Rect(192, 0, 64, 64), Slot4Background))
- {InventoryFieldSelected = 4;}
- //InventoryField5
- if (GUI.Button(new Rect(256, 0, 64, 64), Slot5Background))
- {InventoryFieldSelected = 5;}
- //InventoryField6
- if (GUI.Button(new Rect(320, 0, 64, 64), Slot6Background))
- {InventoryFieldSelected = 6;}
- //InventoryField7
- if (GUI.Button(new Rect(384, 0, 64, 64), Slot7Background))
- {InventoryFieldSelected = 7;}
- //InventoryField8
- if (GUI.Button(new Rect(448, 0, 64, 64), Slot8Background))
- {InventoryFieldSelected = 8;}
- //InventoryField9
- if (GUI.Button(new Rect(512, 0, 64, 64), Slot9Background))
- {InventoryFieldSelected = 9;}
- //InventoryField0
- if (GUI.Button(new Rect(576, 0, 64, 64), Slot0Background))
- {InventoryFieldSelected = 0;}
- GUI.EndGroup();
- }
- void PickUpItem()
- {
- //=============================================
- //== FIND FREE SLOT // CHANGE ITEMINSLOT VAR ==
- //=============================================
- //Transfer ItemToPickUp into Slot1 if free
- if (ItemInSlot1 == 0){ItemInSlot1 = ItemToPickUp; SlotToTransferPickUp = 1; ItemToPickUp = 0;}
- //Transfer ItemToPickUp into Slot2 if free
- if (ItemInSlot2 == 0){ItemInSlot2 = ItemToPickUp; SlotToTransferPickUp = 2; ItemToPickUp = 0;}
- //Transfer ItemToPickUp into Slot3 if free
- if (ItemInSlot3 == 0){ItemInSlot3 = ItemToPickUp; SlotToTransferPickUp = 3; ItemToPickUp = 0;}
- //Transfer ItemToPickUp into Slot4 if free
- if (ItemInSlot4 == 0){ItemInSlot4 = ItemToPickUp; SlotToTransferPickUp = 4; ItemToPickUp = 0;}
- //Transfer ItemToPickUp into Slot5 if free
- if (ItemInSlot5 == 0){ItemInSlot5 = ItemToPickUp; SlotToTransferPickUp = 5; ItemToPickUp = 0;}
- //Transfer ItemToPickUp into Slot6 if free
- if (ItemInSlot6 == 0){ItemInSlot6 = ItemToPickUp; SlotToTransferPickUp = 6; ItemToPickUp = 0;}
- //Transfer ItemToPickUp into Slot7 if free
- if (ItemInSlot7 == 0){ItemInSlot7 = ItemToPickUp; SlotToTransferPickUp = 7; ItemToPickUp = 0;}
- //Transfer ItemToPickUp into Slot8 if free
- if (ItemInSlot8 == 0){ItemInSlot8 = ItemToPickUp; SlotToTransferPickUp = 8; ItemToPickUp = 0;}
- //Transfer ItemToPickUp into Slot9 if free
- if (ItemInSlot9 == 0){ItemInSlot9 = ItemToPickUp; SlotToTransferPickUp = 9; ItemToPickUp = 0;}
- //Transfer ItemToPickUp into Slot0 if free
- if (ItemInSlot0 == 0){ItemInSlot0 = ItemToPickUp; SlotToTransferPickUp = 0; ItemToPickUp = 0;}
- PickUpItem2();
- }
- void PickUpItem2()
- {
- //=============================================
- //== CHANGE SLOT TEXTURE TO ITEM ICON =========
- //=============================================
- //== second problem ===========================
- if (ItemToPickUp == 1){
- if (SlotToTransferPickUp == 1){ItemIconSlot1 = InventoryIconHammer;}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement