Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Inv {
- public var item : MicrowaveItem;
- public var name : String;
- public var description : String;
- public var quantity : int;
- public var siz : int;
- public var rh : boolean; // restore health
- public var rmh : boolean; // restore microwave health
- public var texture : Texture2D;
- }
- var inv : Inv[];
- private var scrollPosition : Vector2;
- private var scrollPosition2 : Vector2;
- private var srh : boolean = false;
- private var srmh : boolean = false;
- private var show : boolean = false;
- private var item : int;
- private var nam : String;
- private var micitems : int[];
- private var msize : int = 10;
- private var temparr = Array();
- function OnGUI () {
- if (Camera.main.transform.GetComponent("main").ms==1) {
- if (GUI.Button(Rect(0,0,150,30),"Return to main menu")) {
- Camera.main.transform.GetComponent("main").ms=0;
- }
- GUI.Box(Rect(Screen.width-300,40,300,Screen.height-80),"");
- GUI.Box(Rect(0,40,Screen.width-310,((Screen.height-80)/2)-5),"");
- GUI.Box(Rect(0,((Screen.height-80)/2)+45,Screen.width-310,((Screen.height-80)/2)-5),"");
- // inventory list---------------------------------------------------------------------------------------
- GUILayout.BeginArea (Rect (Screen.width-300,40,300,Screen.height-80));
- scrollPosition = GUILayout.BeginScrollView (scrollPosition, GUILayout.Width (300), GUILayout.Height (Screen.height-80));
- GUILayout.BeginVertical ("");
- for (var i = 0;i<inv.length;i++) {
- if (inv[i].quantity>0) {
- GUILayout.BeginHorizontal("");
- if (GUILayout.Button(inv[i].texture,GUILayout.Width(75))) {
- //inv[i].quantity=inv[i].quantity-1;
- show = true;
- item = i;
- nam = inv[i].name;
- }
- GUILayout.BeginVertical ("");
- GUILayout.Label(inv[i].name);
- GUILayout.Label(""+inv[i].quantity);
- GUILayout.EndVertical();
- GUILayout.EndHorizontal();
- }
- }
- GUILayout.EndVertical();
- GUILayout.EndScrollView ();
- GUILayout.EndArea ();
- if (show && inv[item].quantity>0) {
- // item description------------------------------------------------------------------------------
- GUILayout.BeginArea (Rect(0,40,Screen.width-310,((Screen.height-80)/2)-5));
- GUILayout.BeginVertical ("");
- GUILayout.BeginHorizontal("");
- GUILayout.Label(inv[item].texture,GUILayout.Width (64));
- GUILayout.BeginVertical ("");
- GUILayout.Label(inv[item].name);
- GUILayout.Label("number in inventory = "+inv[item].quantity+", item size = "+inv[item].siz);
- GUILayout.EndVertical();
- GUILayout.EndHorizontal();
- GUILayout.Label(inv[item].description);
- GUILayout.EndVertical();
- GUILayout.EndArea ();
- if (inv[item].siz>msize) {
- GUI.enabled = false;
- }
- if (GUI.Button(Rect(0,((Screen.height-80)/2)+5,Screen.width-310,30),"Add "+nam+" to microwave")) {
- //show=false;
- AddToMicrowave(item);
- }
- GUI.enabled = true;
- }
- // microwave item list--------------------------------------------------------------------------------
- GUILayout.BeginArea (Rect(0,((Screen.height-80)/2)+45,Screen.width-310,((Screen.height-80)/2)-5));
- scrollPosition2 = GUILayout.BeginScrollView (scrollPosition2, GUILayout.Width (Screen.width-310), GUILayout.Height (((Screen.height-80)/2)-5));
- GUILayout.BeginVertical ("");
- GUILayout.BeginHorizontal("");
- if (Screen.width-310>360) {
- GUILayout.Space((Screen.width-310-360)/2);
- }
- if (micitems != null && micitems.length>0) {
- for (k=0;k<micitems.length&&k!=5;k++) {
- GUILayout.BeginVertical ("",GUILayout.Width(50));
- GUILayout.Label(inv[micitems[k]].texture);
- if (GUILayout.Button("remove")) {
- RemoveFromMicrowave(k);
- }
- GUILayout.EndVertical();
- }
- }
- GUILayout.EndHorizontal();
- if (micitems != null && micitems.length>5) {
- GUILayout.BeginHorizontal("");
- if (Screen.width-310>360) {
- GUILayout.Space((Screen.width-310-360)/2);
- }
- if (micitems != null && micitems.length>0) {
- for (k=5;k<micitems.length;k++) {
- GUILayout.BeginVertical ("",GUILayout.Width(50));
- GUILayout.Label(inv[micitems[k]].texture);
- if (GUILayout.Button("remove")) {
- RemoveFromMicrowave(k);
- }
- GUILayout.EndVertical();
- }
- }
- GUILayout.EndHorizontal();
- }
- GUILayout.EndVertical();
- GUILayout.EndScrollView ();
- GUILayout.EndArea ();
- //Rect(0,Screen.height-30,Screen.width,30),"add "+nam+" to microwave")
- }
- }
- function RemoveFromMicrowave(ite:int) {
- inv[micitems[ite]].quantity = inv[micitems[ite]].quantity + 1;
- msize = msize + inv[micitems[ite]].siz;
- temparr = new Array (micitems);
- temparr.RemoveAt(ite);
- micitems = temparr.ToBuiltin(int);
- }
- function AddToMicrowave (it : int) {
- inv[it].quantity = inv[it].quantity - 1;
- msize = msize - inv[it].siz;
- if (micitems!=null)
- temparr = new Array (micitems);
- temparr.Push(it);
- micitems = temparr.ToBuiltin(int);
- //Debug.Log("works");
- //Camera.main.transform.GetComponent("main").ms=0;
- }
- function Update() {
- if (Camera.main.transform.GetComponent("main").ms==0) {
- show=false;
- scrollPosition = Vector2.zero;
- scrollPosition2 = Vector2.zero;
- }
- /*msize = 10;
- if (micitems != null && micitems.length>0) {
- for (j=0;j<micitems.length;j++) {
- msize = msize - inv[micitems[j]].siz;
- }
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement