Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System.Collections.Generic; //is required for lists
- var ItemName : List.<String>; //makes a list for item names but can only accept strings
- 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.
- var Direction : float; //remove unless you want your object rotating. see line 63
- var Index : int; //is used to check the index of an item
- var Items : int; //keeps track of items that are in the ItemNumber so the menu is shown correctly.
- function AddItem(item, number){ //Function for adding items
- if(ItemName.Contains(item)){ //checks if the item is in the list via name
- Index = ItemName.IndexOf(item); //gets the index of that item if it exists
- ItemNumber[Index] += number; //increases that item by the number you set via command
- }//ends checking if item exists
- else{ // if it doesnt find that item in the list it will add it to the end of the current list
- ItemName.Add(item); //add item name
- ItemNumber.Add(number); //add item number
- }
- }
- function RemoveItem(item, number){ //Function for adding items
- if(ItemName.Contains(item)){ //checks if the item is in the list via name
- Index = ItemName.IndexOf(item); //gets the index of that item if it exists
- ItemNumber[Index] -= number; //increases that item by the number you set via command
- if(ItemNumber[Index] <= 0){
- ItemName.RemoveAt(Index);
- ItemNumber.RemoveAt(Index);
- }
- }//ends checking if item exists
- }
- function OnGUI(){ //used to display gui duh :P
- if(Items >= 1){ //only show if items are = or more than 1 or else error will happen and prevent rest of script from loading
- GUI.Label(Rect(10,20*1,200,21), "Item: "+ItemName[0]+" x"+ItemNumber[0]); //displays item #1 in the list
- }
- if(Items >= 2){ //only show if items are = or more than 2 or else error will happen and prevent rest of script from loading
- GUI.Label(Rect(10,20*2,200,21), "Item: "+ItemName[1]+" x"+ItemNumber[1]); //displays item #2 in the list
- }
- if(Items >= 3){ //only show if items are = or more than 2 or else error will happen and prevent rest of script from loading
- GUI.Label(Rect(10,20*3,200,21), "Item: "+ItemName[2]+" x"+ItemNumber[2]); //displays item #3 in the list
- }
- if(Items >= 4){ //only show if items are = or more than 3 or else error will happen and prevent rest of script from loading
- GUI.Label(Rect(10,20*4,200,21), "Item: "+ItemName[3]+" x"+ItemNumber[3]); //displays item #4 in the list
- }
- if(Items >= 5){ //only show if items are = or more than 4 or else error will happen and prevent rest of script from loading
- GUI.Label(Rect(10,20*5,200,21), "Item: "+ItemName[4]+" x"+ItemNumber[4]); //displays item #5 in the list
- }
- if(GUI.Button(Rect(10,22*7,75,21), "Add Potion")){//button for adding item
- AddItem("Potion", 1); //will add an item with that name and that ammount
- }
- if(GUI.Button(Rect(10,22*8,75,21), "Add Ether")){//button for adding item
- AddItem("Ether", 1);//will add an item with that name and that ammount
- }
- if(GUI.Button(Rect(10,22*9,75,21), "Add Weed")){//button for adding item
- AddItem("Weed", 1);//will add an item with that name and that ammount
- }
- if(GUI.Button(Rect(10,22*10,75,21), "Add Sword")){//button for adding item
- AddItem("Sword", 1);//will add an item with that name and that ammount
- }
- if(GUI.Button(Rect(10,22*11,90,21), "Add Condom")){//button for adding condoms better to be safe than sorry :D
- AddItem("Condom", 1);//will add an item with that name and that ammount
- }
- if(GUI.Button(Rect(10*12,22*7,101,21), "Remove Potion")){//button for adding item
- RemoveItem("Potion", 1); //will add an item with that name and that ammount
- }
- if(GUI.Button(Rect(10*12,22*8,100,21), "Remove Ether")){//button for adding item
- RemoveItem("Ether", 1);//will add an item with that name and that ammount
- }
- if(GUI.Button(Rect(10*12,22*9,100,21), "Remove Weed")){//button for adding item
- RemoveItem("Weed", 1);//will add an item with that name and that ammount
- }
- if(GUI.Button(Rect(10*12,22*10,100,21), "Remove Sword")){//button for adding item
- RemoveItem("Sword", 1);//will add an item with that name and that ammount
- }
- if(GUI.Button(Rect(10*12,22*11,115,21), "Remove Condom")){//button for adding condoms better to be safe than sorry :D
- RemoveItem("Condom", 1);//will add an item with that name and that ammount
- }
- }
- function Update () {//what happens every frame
- Items = ItemNumber.Count;//will update the ammount of items in the list
- transform.Rotate (Vector3.forward* Direction);// remove unless you want your object rotating
- }//ends update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement