Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. public class Inventory : MonoBehaviour
  7. {
  8. public Item[] itemsinInventory;
  9. public Item blankItem;
  10. public Texture2D box;
  11. public Texture2D highlighted;
  12. public int selectedItem;
  13. public int maxItem = 7;
  14.  
  15.  
  16. void Start()
  17. {
  18. for (int i = 0; i < maxItem; i++)
  19. {
  20. itemsinInventory[i] = blankItem;
  21. }
  22.  
  23.  
  24. }
  25.  
  26. public void addItem(Item a)
  27. {
  28. for (int i = 0; i < maxItem; i++)
  29. {
  30. if(itemsinInventory[i] = blankItem)
  31. {
  32. itemsinInventory[i] = a;
  33.  
  34. return;
  35. }
  36. }
  37. }
  38.  
  39. public void removeItem()
  40. {
  41. itemsinInventory [selectedItem].useItem ();
  42.  
  43. for (int i = selectedItem; i < maxItem-1; i++)
  44. {
  45. itemsinInventory[i] = itemsinInventory[i+1];
  46. }
  47.  
  48. itemsinInventory [maxItem-1] = blankItem;
  49. }
  50.  
  51. void Update()
  52. {
  53. if (Input.GetAxis ("Scroll") > 0)
  54. {
  55. if(selectedItem == maxItem-1)
  56. selectedItem = 0;
  57. else
  58. selectedItem++;
  59. }
  60.  
  61. if (Input.GetAxis ("Scroll") < 0)
  62. {
  63. if(selectedItem == 0)
  64. selectedItem = maxItem-1;
  65. else
  66. selectedItem--;
  67. }
  68.  
  69. if (Input.GetKeyUp (KeyCode.G)) {
  70. removeItem ();
  71. }
  72. }
  73.  
  74. void OnGUI()
  75. {
  76. for (int i = 0; i < maxItem; i++)
  77. {
  78. if(i == selectedItem)
  79. {
  80. GUI.DrawTexture (new Rect ((i * 70)+330, 600, 60, 60), selectedItem);
  81. }
  82.  
  83. else if (itemsinInventory [i] != blankItem)
  84. {
  85. GUI.Box (new Rect ((i * 70)+330, 600, 60, 60), itemsinInventory [i].Icon);
  86.  
  87. }
  88. else
  89. {
  90. GUI.Box (new Rect ((i * 70)+330, 600, 60, 60), "");
  91. }
  92.  
  93. }
  94. }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement