Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import System.Collections.Generic; //is required for lists
  2.  
  3. var ItemName : List.<String>; //makes a list for item names but can only accept strings
  4. var ItemNumber : List.<int>; //makes a list for item numbers but can only accept ints, best for ints as they cant have decimals and is super useful for later if you want to half items without having decimals.
  5. var Direction : float; //remove unless you want your object rotating. see line 63
  6. var Index : int; //is used to check the index of an item
  7. var Items : int; //keeps track of items that are in the ItemNumber so the menu is shown correctly.
  8.  
  9.  
  10. function AddItem(item, number){ //Function for adding items
  11.  
  12. if(ItemName.Contains(item)){ //checks if the item is in the list via name
  13.     Index = ItemName.IndexOf(item); //gets the index of that item if it exists
  14.     ItemNumber[Index] += number; //increases that item by the number you set via command
  15. }//ends checking if item exists
  16. else{ // if it doesnt find that item in the list it will add it to the end of the current list
  17.     ItemName.Add(item); //add item name
  18.     ItemNumber.Add(number); //add item number
  19. }
  20. }
  21.  
  22. function RemoveItem(item, number){ //Function for adding items
  23.  
  24. if(ItemName.Contains(item)){ //checks if the item is in the list via name
  25.     Index = ItemName.IndexOf(item); //gets the index of that item if it exists
  26.     ItemNumber[Index] -= number; //increases that item by the number you set via command
  27.     if(ItemNumber[Index] <= 0){
  28.         ItemName.RemoveAt(Index);
  29.         ItemNumber.RemoveAt(Index);
  30.     }
  31. }//ends checking if item exists
  32. }
  33.  
  34.  
  35.  
  36. function OnGUI(){ //used to display gui duh :P
  37.  
  38. if(Items >= 1){ //only show if items are = or more than 1 or else error will happen and prevent rest of script from loading
  39. GUI.Label(Rect(10,20*1,200,21), "Item: "+ItemName[0]+" x"+ItemNumber[0]); //displays item #1 in the list
  40. }
  41. if(Items >= 2){ //only show if items are = or more than 2 or else error will happen and prevent rest of script from loading
  42. GUI.Label(Rect(10,20*2,200,21), "Item: "+ItemName[1]+" x"+ItemNumber[1]);  //displays item #2 in the list
  43. }
  44. if(Items >= 3){ //only show if items are = or more than 2 or else error will happen and prevent rest of script from loading
  45. GUI.Label(Rect(10,20*3,200,21), "Item: "+ItemName[2]+" x"+ItemNumber[2]);  //displays item #3 in the list
  46. }
  47. if(Items >= 4){ //only show if items are = or more than 3 or else error will happen and prevent rest of script from loading
  48. GUI.Label(Rect(10,20*4,200,21), "Item: "+ItemName[3]+" x"+ItemNumber[3]); //displays item #4 in the list
  49. }
  50. if(Items >= 5){ //only show if items are = or more than 4 or else error will happen and prevent rest of script from loading
  51. GUI.Label(Rect(10,20*5,200,21), "Item: "+ItemName[4]+" x"+ItemNumber[4]); //displays item #5 in the list
  52. }
  53.  
  54. if(GUI.Button(Rect(10,22*7,75,21), "Add Potion")){//button for adding item
  55.     AddItem("Potion", 1); //will add an item with that name and that ammount
  56. }
  57. if(GUI.Button(Rect(10,22*8,75,21), "Add Ether")){//button for adding item
  58.     AddItem("Ether", 1);//will add an item with that name and that ammount
  59. }
  60. if(GUI.Button(Rect(10,22*9,75,21), "Add Weed")){//button for adding item
  61.     AddItem("Weed", 1);//will add an item with that name and that ammount
  62. }
  63. if(GUI.Button(Rect(10,22*10,75,21), "Add Sword")){//button for adding item
  64.     AddItem("Sword", 1);//will add an item with that name and that ammount
  65. }
  66. if(GUI.Button(Rect(10,22*11,90,21), "Add Condom")){//button for adding condoms better to be safe than sorry :D
  67.     AddItem("Condom", 1);//will add an item with that name and that ammount
  68. }
  69.  
  70.  
  71. if(GUI.Button(Rect(10*12,22*7,101,21), "Remove Potion")){//button for adding item
  72.     RemoveItem("Potion", 1); //will add an item with that name and that ammount
  73. }
  74. if(GUI.Button(Rect(10*12,22*8,100,21), "Remove Ether")){//button for adding item
  75.     RemoveItem("Ether", 1);//will add an item with that name and that ammount
  76. }
  77. if(GUI.Button(Rect(10*12,22*9,100,21), "Remove Weed")){//button for adding item
  78.     RemoveItem("Weed", 1);//will add an item with that name and that ammount
  79. }
  80. if(GUI.Button(Rect(10*12,22*10,100,21), "Remove Sword")){//button for adding item
  81.     RemoveItem("Sword", 1);//will add an item with that name and that ammount
  82. }
  83. if(GUI.Button(Rect(10*12,22*11,115,21), "Remove Condom")){//button for adding condoms better to be safe than sorry :D
  84.     RemoveItem("Condom", 1);//will add an item with that name and that ammount
  85. }
  86. }
  87.  
  88.  
  89. function Update () {//what happens every frame
  90. Items = ItemNumber.Count;//will update the ammount of items in the list
  91. transform.Rotate (Vector3.forward* Direction);// remove unless you want your object rotating
  92. }//ends update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement