Advertisement
Guest User

HUDInventory.cs

a guest
Aug 10th, 2011
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.70 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class HUDInventory : MonoBehaviour {
  5.  
  6.  
  7.    
  8. //Inventory Variables
  9. public int InventoryFieldSelected = 1;
  10. public int ActiveItem = 0;
  11. public int InventoryFromTop = 600;
  12. public int ItemToPickUp = 0;
  13. public int SlotToTransferPickUp = 0;
  14.  
  15. //  Slots Background Textures
  16. public Texture Slot1Background;
  17. public Texture Slot2Background;
  18. public Texture Slot3Background;
  19. public Texture Slot4Background;
  20. public Texture Slot5Background;
  21. public Texture Slot6Background;
  22. public Texture Slot7Background;
  23. public Texture Slot8Background;
  24. public Texture Slot9Background;
  25. public Texture Slot0Background;
  26.  
  27. //Item Icons generally
  28.     //0
  29. static public Texture InventoryIconEmpty;
  30.     //1
  31. public Texture InventoryIconHammer;
  32.     //2
  33. public Texture InventoryIconPipe;
  34.  
  35. //Item Icon for Slot
  36. public Texture ItemIconSlot1 = InventoryIconEmpty;
  37. public Texture ItemIconSlot2;
  38. public Texture ItemIconSlot3;
  39. public Texture ItemIconSlot4;
  40. public Texture ItemIconSlot5;
  41. public Texture ItemIconSlot6;
  42. public Texture ItemIconSlot7;
  43. public Texture ItemIconSlot8;
  44. public Texture ItemIconSlot9;
  45. public Texture ItemIconSlot0;
  46.    
  47. // What Item is in Slot?
  48. public int ItemInSlot1 = 0;
  49. public int ItemInSlot2 = 0;
  50. public int ItemInSlot3 = 0;
  51. public int ItemInSlot4 = 0;
  52. public int ItemInSlot5 = 0;
  53. public int ItemInSlot6 = 0;
  54. public int ItemInSlot7 = 0;
  55. public int ItemInSlot8 = 0;
  56. public int ItemInSlot9 = 0;
  57. public int ItemInSlot0 = 0;
  58.    
  59.     // Use this for initialization
  60.     void Start () {
  61.    
  62.     }
  63.    
  64.     // Update is called once per frame
  65.     void Update () {
  66.  
  67.     //Select Fields per Keyboard   
  68.     if(Input.GetKeyUp("1")){InventoryFieldSelected = 1;}
  69.     if(Input.GetKeyUp("2")){InventoryFieldSelected = 2;}
  70.     if(Input.GetKeyUp("3")){InventoryFieldSelected = 3;}
  71.     if(Input.GetKeyUp("4")){InventoryFieldSelected = 4;}
  72.     if(Input.GetKeyUp("5")){InventoryFieldSelected = 5;}
  73.     if(Input.GetKeyUp("6")){InventoryFieldSelected = 6;}
  74.     if(Input.GetKeyUp("7")){InventoryFieldSelected = 7;}
  75.     if(Input.GetKeyUp("8")){InventoryFieldSelected = 8;}
  76.     if(Input.GetKeyUp("9")){InventoryFieldSelected = 9;}
  77.     if(Input.GetKeyUp("0")){InventoryFieldSelected = 0;}
  78.     //TEST PICK UP HAMMER
  79.     if(Input.GetKeyUp("h")){ItemToPickUp = 1; PickUpItem();}
  80.        
  81.     //Set ActiveItem
  82.     if (InventoryFieldSelected == 1){ActiveItem = ItemInSlot1;}
  83.     if (InventoryFieldSelected == 2){ActiveItem = ItemInSlot2;}
  84.     if (InventoryFieldSelected == 3){ActiveItem = ItemInSlot3;}
  85.     if (InventoryFieldSelected == 4){ActiveItem = ItemInSlot4;}
  86.     if (InventoryFieldSelected == 5){ActiveItem = ItemInSlot5;}
  87.     if (InventoryFieldSelected == 6){ActiveItem = ItemInSlot6;}
  88.     if (InventoryFieldSelected == 7){ActiveItem = ItemInSlot7;}
  89.     if (InventoryFieldSelected == 8){ActiveItem = ItemInSlot8;}
  90.     if (InventoryFieldSelected == 9){ActiveItem = ItemInSlot9;}
  91.     if (InventoryFieldSelected == 0){ActiveItem = ItemInSlot0;}
  92.        
  93.     //Send ActiveItem to PlayerAttack.cs
  94.     PlayerAttack.ActiveItem = ActiveItem;
  95.     }
  96.  
  97.  
  98.  
  99.  
  100.     void OnGUI ()
  101.     {
  102.     GUI.BeginGroup(new Rect(500, InventoryFromTop, 640, 64));
  103.     //GUI.contentColor = Color.yellow;
  104.        
  105.     //InventoryField1
  106.     //======= first problem ====================================
  107.     //==========================================================
  108.     //== I want to Add the following line the all Slots ========
  109.     //== to display an image of the Item that is in this Slot
  110.     //== If i add this line, the whole inventory isnt displayed anymore
  111.     //==========================================================
  112.     //==========================================================
  113.     //GUI.DrawTexture(new Rect(0,0,64,64), ItemIconSlot1);
  114.     if (GUI.Button(new Rect(0, 0, 64, 64), Slot1Background))
  115.         {InventoryFieldSelected = 1;}
  116.  
  117.     //InventoryField2
  118.     if (GUI.Button(new Rect(64, 0, 64, 64), Slot2Background))
  119.         {InventoryFieldSelected = 2;}
  120.        
  121.     //InventoryField3
  122.     if (GUI.Button(new Rect(128, 0, 64, 64), Slot3Background))
  123.         {InventoryFieldSelected = 3;}
  124.        
  125.     //InventoryField4
  126.     if (GUI.Button(new Rect(192, 0, 64, 64), Slot4Background))
  127.         {InventoryFieldSelected = 4;}
  128.        
  129.     //InventoryField5
  130.     if (GUI.Button(new Rect(256, 0, 64, 64), Slot5Background))
  131.         {InventoryFieldSelected = 5;}
  132.        
  133.     //InventoryField6
  134.     if (GUI.Button(new Rect(320, 0, 64, 64), Slot6Background))
  135.         {InventoryFieldSelected = 6;}
  136.        
  137.     //InventoryField7
  138.     if (GUI.Button(new Rect(384, 0, 64, 64), Slot7Background))
  139.         {InventoryFieldSelected = 7;}
  140.        
  141.     //InventoryField8
  142.     if (GUI.Button(new Rect(448, 0, 64, 64), Slot8Background))
  143.         {InventoryFieldSelected = 8;}
  144.        
  145.     //InventoryField9
  146.     if (GUI.Button(new Rect(512, 0, 64, 64), Slot9Background))
  147.         {InventoryFieldSelected = 9;}
  148.        
  149.     //InventoryField0
  150.     if (GUI.Button(new Rect(576, 0, 64, 64), Slot0Background))
  151.         {InventoryFieldSelected = 0;}
  152.    
  153.     GUI.EndGroup();
  154.        
  155.     }
  156.    
  157.     void PickUpItem()
  158.     {
  159.     //=============================================
  160.     //== FIND FREE SLOT // CHANGE ITEMINSLOT VAR ==
  161.     //=============================================
  162.     //Transfer ItemToPickUp into Slot1 if free
  163.     if (ItemInSlot1 == 0){ItemInSlot1 = ItemToPickUp; SlotToTransferPickUp = 1; ItemToPickUp = 0;}
  164.        
  165.     //Transfer ItemToPickUp into Slot2 if free
  166.     if (ItemInSlot2 == 0){ItemInSlot2 = ItemToPickUp; SlotToTransferPickUp = 2; ItemToPickUp = 0;}
  167.        
  168.     //Transfer ItemToPickUp into Slot3 if free
  169.     if (ItemInSlot3 == 0){ItemInSlot3 = ItemToPickUp; SlotToTransferPickUp = 3; ItemToPickUp = 0;}
  170.        
  171.     //Transfer ItemToPickUp into Slot4 if free
  172.     if (ItemInSlot4 == 0){ItemInSlot4 = ItemToPickUp; SlotToTransferPickUp = 4; ItemToPickUp = 0;}
  173.        
  174.     //Transfer ItemToPickUp into Slot5 if free
  175.     if (ItemInSlot5 == 0){ItemInSlot5 = ItemToPickUp; SlotToTransferPickUp = 5; ItemToPickUp = 0;}
  176.        
  177.     //Transfer ItemToPickUp into Slot6 if free
  178.     if (ItemInSlot6 == 0){ItemInSlot6 = ItemToPickUp; SlotToTransferPickUp = 6; ItemToPickUp = 0;}
  179.        
  180.     //Transfer ItemToPickUp into Slot7 if free
  181.     if (ItemInSlot7 == 0){ItemInSlot7 = ItemToPickUp; SlotToTransferPickUp = 7; ItemToPickUp = 0;}
  182.        
  183.     //Transfer ItemToPickUp into Slot8 if free
  184.     if (ItemInSlot8 == 0){ItemInSlot8 = ItemToPickUp; SlotToTransferPickUp = 8; ItemToPickUp = 0;}
  185.        
  186.     //Transfer ItemToPickUp into Slot9 if free
  187.     if (ItemInSlot9 == 0){ItemInSlot9 = ItemToPickUp; SlotToTransferPickUp = 9; ItemToPickUp = 0;}
  188.        
  189.     //Transfer ItemToPickUp into Slot0 if free
  190.     if (ItemInSlot0 == 0){ItemInSlot0 = ItemToPickUp; SlotToTransferPickUp = 0; ItemToPickUp = 0;}
  191.    
  192.         PickUpItem2();
  193.        
  194.     }
  195.    
  196.     void PickUpItem2()
  197.     {
  198.         //=============================================
  199.         //== CHANGE SLOT TEXTURE TO ITEM ICON =========
  200.         //=============================================
  201.         //== second problem ===========================
  202.         if (ItemToPickUp == 1){
  203.             if (SlotToTransferPickUp == 1){ItemIconSlot1 = InventoryIconHammer;}
  204.            
  205.         }
  206.        
  207.    
  208.     }
  209.    
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement