Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by norman1234 · Feb 06, 2014 at 03:32 PM · javascriptinventoryinventory system

How to optimize this script and add items imediately without grids

How can i optimize this inventory script. And also pick up items and drop them. The items are in c#. i Tried converting this script but to no avail.

 #pragma strict
 //Private Variables
 private var InventoryOn = false;
 private var scrollBarChopGrid : Vector2 = Vector2.zero;
 private var GridValue : float = -1;
 var myskin : GUISkin;
 
 //GUI Pos/Size
 var ClosePosition : Vector2 = new Vector2(312,5);
 var CloseSize : Vector2 = new Vector2(35,35);
 var NamePosition : Vector2 = new Vector2(13,13);
 var NameSize : Vector2 = new Vector2(250,250);
 var TooltipSize : Vector2 = new Vector2(140,40);
 var GridPosition : Vector2 = new Vector2(10,2);
 var GridSize : Vector2 = new Vector2(323,410);
 var ScrollPosition : Vector2 = new Vector2(0,95);
 var ScrollSize : Vector2 = new Vector2(353,257);
 var WindowPosition : Vector2 = new Vector2(0,0);
 var WindowSize : Vector2 = new Vector2(360,360);
 var DragWindowPosition : Rect = Rect(0, 0, WindowSize.x, WindowSize.y);
 
 //Textures
 var InventoryWindow : Texture;
 var CloseIcon : Texture;
 var Grids : GUIContent[];
 
 
 function Update () {
     //On or Off
     if (Input.GetKeyUp("i"))
     {
         if (InventoryOn == false)
         {
             InventoryOn = true;
         }
         else if (InventoryOn == true)
         {
             InventoryOn = false;
             scrollBarChopGrid.y= 0;
         }
     }
     //Window Drag fix
     if (Input.GetKeyDown("left shift"))
     {
     if (Input.GetKeyDown("i"))
     {
     DragWindowPosition.x = 10;
     DragWindowPosition.y = 10;
     }
     }
     }
 function OnGUI()
 {
     GUI.skin = myskin;
     if (InventoryOn == true)
     {
         DragWindowPosition = GUI.Window(0, DragWindowPosition, DoMyWindow, "");
         
         if (GridValue != 0 && GUI.tooltip != ""){
         {
     GUI.Box(Rect (Event.current.mousePosition.x, Screen.height - Input.mousePosition.y + 15, TooltipSize.x,TooltipSize.y), Grids[GridValue].tooltip);
 }
 
         }
 
     }
 }
 
 function DoMyWindow(windowID : int){
 
          if (InventoryOn == true)
     {
         GUI.BeginGroup(new Rect(WindowPosition.x, WindowPosition.y, WindowSize.x, WindowSize.y), InventoryWindow);
            //Name
            GUI.Label (Rect (NamePosition.x, NamePosition.y,NameSize.x, NameSize.y),"Your Inventory"); 
          //Close Button
         if (GUI.Button(Rect(ClosePosition.x, ClosePosition.y, CloseSize.x, CloseSize.y), CloseIcon))
         {
             InventoryOn = false;
         }
         //Scroll Bar
         scrollBarChopGrid = GUI.BeginScrollView(Rect (ScrollPosition.x, ScrollPosition.y, ScrollSize.x, ScrollSize.y), scrollBarChopGrid, Rect(0,0,0,420));
             // Grid
             GridValue = GUI.SelectionGrid(Rect(GridPosition.x, GridPosition.y, GridSize.x, GridSize.y), GridValue, Grids, 5);
         GUI.EndScrollView();
     //Dragable Window
     GUI.DragWindow (Rect (WindowPosition.x, WindowPosition.y, 10000, 40));
         GUI.EndGroup();
     }
 }
 
 
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Inventory code not working [JS] 0 Answers

Having scripts interact 1 Answer

Is this considered bad coding 1 Answer

Locked door and key to open it script 1 Answer

How to simplify my Equipment method? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges