Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class Inventory : MonoBehaviour
- {
- public Item[] itemsinInventory;
- public Item blankItem;
- public Texture2D box;
- public Texture2D highlighted;
- public int selectedItem;
- public int maxItem = 7;
- void Start()
- {
- for (int i = 0; i < maxItem; i++)
- {
- itemsinInventory[i] = blankItem;
- }
- }
- public void addItem(Item a)
- {
- for (int i = 0; i < maxItem; i++)
- {
- if(itemsinInventory[i] = blankItem)
- {
- itemsinInventory[i] = a;
- return;
- }
- }
- }
- public void removeItem()
- {
- itemsinInventory [selectedItem].useItem ();
- for (int i = selectedItem; i < maxItem-1; i++)
- {
- itemsinInventory[i] = itemsinInventory[i+1];
- }
- itemsinInventory [maxItem-1] = blankItem;
- }
- void Update()
- {
- if (Input.GetAxis ("Scroll") > 0)
- {
- if(selectedItem == maxItem-1)
- selectedItem = 0;
- else
- selectedItem++;
- }
- if (Input.GetAxis ("Scroll") < 0)
- {
- if(selectedItem == 0)
- selectedItem = maxItem-1;
- else
- selectedItem--;
- }
- if (Input.GetKeyUp (KeyCode.G)) {
- removeItem ();
- }
- }
- void OnGUI()
- {
- for (int i = 0; i < maxItem; i++)
- {
- if(i == selectedItem)
- {
- GUI.DrawTexture (new Rect ((i * 70)+330, 600, 60, 60), selectedItem);
- }
- else if (itemsinInventory [i] != blankItem)
- {
- GUI.Box (new Rect ((i * 70)+330, 600, 60, 60), itemsinInventory [i].Icon);
- }
- else
- {
- GUI.Box (new Rect ((i * 70)+330, 600, 60, 60), "");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement