Advertisement
Guest User

Chest.cs

a guest
Mar 14th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.18 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Chest : MonoBehaviour {
  6.  
  7.     public List<Item> chestInventory = new List<Item>();
  8.     public List<Item> playerInventory = Inventory.mainInventory;
  9.     private Vector2 scrollChest;
  10.     private Vector2 scrollMine;
  11.  
  12.     public string chestName;
  13.  
  14.     string currentMenu = "";
  15.  
  16.     bool canClick = false;
  17.     bool canOpen = false;
  18.     bool open = false;
  19.  
  20.     public GameObject player;
  21.  
  22.     void Start() {
  23.    
  24.     }
  25.  
  26.     void Update() {
  27.         if(Input.GetKeyDown(KeyCode.F) && canClick == true && canOpen == true) {
  28.             open = true;
  29.         }
  30.  
  31.         if(open == true) {
  32.             currentMenu = "Sel";
  33.             player.GetComponent<FirstPersonController>().enabled = false;
  34.             //player.GetComponent<BasicSettings>().enabled = false;
  35.         } else if(open == false) {
  36.             currentMenu = "";
  37.             player.GetComponent<FirstPersonController>().enabled = true;
  38.             //player.GetComponent<BasicSettings>().enabled = true;
  39.         }
  40.     }
  41.  
  42.     public void NavigateTo(string nextmenu) {
  43.         currentMenu = nextmenu;
  44.     }
  45.  
  46.     void OnGUI() {
  47.         if(currentMenu == "Sel")
  48.             InvSelect();
  49.         if(currentMenu == "Chest")
  50.             InvChest();
  51.         if(currentMenu == "Mine")
  52.             InvMine();
  53.     }
  54.  
  55.     public void InvSelect() {
  56.         GUI.Box(new Rect(0, 0, 200, Screen.height), "Choose Inventory");
  57.         if(GUI.Button(new Rect(10, 40, 180, 30), "Chest")) {
  58.             NavigateTo("Chest");
  59.         }
  60.         if(GUI.Button(new Rect(10, 80, 180, 30), "My Inventory")) {
  61.             NavigateTo("Mine");
  62.         }
  63.         if(GUI.Button(new Rect(10, Screen.height - 40, 180, 30), "Back")) {
  64.             open = false;
  65.             NavigateTo("");
  66.         }
  67.     }
  68.  
  69.     public void InvChest() {
  70.         Debug.Log("InvChest");
  71.         GUI.Box (new Rect(0, 0, 200, Screen.height), "Weapons");
  72.         scrollChest = GUILayout.BeginScrollView(scrollChest, GUILayout.MaxWidth(200));
  73.         GUILayout.Space(40);
  74.             for(int x = 0;x < chestInventory.Count;x++) {
  75.                 if(GUILayout.Button("" + chestInventory[x].name)) {
  76.                     Debug.Log(chestInventory[x].desc);
  77.                 }
  78.             }
  79.         GUILayout.EndArea();
  80.         if(GUI.Button (new Rect(10, Screen.height - 40, 180, 30), "Back")) {
  81.             NavigateTo("Sel");
  82.         }
  83.     }
  84.  
  85.     public void InvMine() {
  86.         Debug.Log("InvMine");
  87.         GUI.Box(new Rect(0, 0, 200, Screen.height), "My Inventory");
  88.         scrollMine = GUILayout.BeginScrollView(scrollMine, GUILayout.MaxWidth(200));
  89.         GUILayout.Space(40);
  90.         for(int x = 0;x < playerInventory.Count;x++) {
  91.             if(GUILayout.Button("" + Inventory.mainInventory[x].name)) {
  92.                 Debug.Log(Inventory.mainInventory[x].desc);
  93.             }
  94.         }
  95.         if(GUI.Button(new Rect(10, Screen.height - 40, 180, 30), "Back")) {
  96.             NavigateTo("Sel");
  97.         }
  98.     }
  99.  
  100.     void OnTriggerEnter(Collider other) {
  101.         canClick = true;
  102.     }
  103.  
  104.     void OnTriggerExit(Collider other){
  105.         canClick = true;
  106.     }
  107.  
  108.     void OnMouseEnter() {
  109.         canOpen = true;
  110.     }
  111.  
  112.     void OnMouseExit() {
  113.         canOpen = false;
  114.     }
  115.  
  116.  
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement