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 Geine · Oct 08, 2012 at 01:08 PM · javascriptguiarraysinventory

Remove Items and Item Tooltips

guys help me with these script, i tried making Tooltips for my items in this inventory system ive made but it doesnt show up, or shows up but not in a way i wanted it to be, also OnGUI doesnt support on LostFocus on a certain GUI Element, i would've wanted to implement those for item removal since i cant think of other ways to do it..

 var itemArray:Texture[] = new Texture[16];
 var itmNm:String[]  = new String[16];
 var itmDes:String[] = new String[16];
 
 var bagCapacity:int = 16;
 
 var bag:Rect;
 
 var ScrollPosition:Vector2 = Vector2.zero;
 
 var dcString:String;
 var dsString:String;
 var cString:String;
 var sString:String;
 
 var cmTex:Texture2D;
 var smTex:Texture2D;
 var dmTex:Texture2D;
 
 var mX:float;
 var mY:float;
 var msX:int =32;
 var msY:int =32;
 var page:int=0;
 
 var cPage:String[] = ["Equipments","Items","Misc"];
 var toggleRemove:boolean = false;
 var toggleBag:boolean = false;
 var lostFocus:boolean = false;
 
 function Start(){
     cmTex = dmTex;
 }
 
 function Update()
 {
     if(Input.GetKeyDown("i"))
     {
        Togglebag();
     }
 }
 
 function OnGUI()
 {
     mX = Input.mousePosition.x;
     mY = Input.mousePosition.y;
     GUI.DrawTexture(Rect((mX-msX/2),((Screen.height-mY)-msY/2+msY/2),msX,msY),cmTex);
 
     if(toggleBag)
     {
         bag = GUI.Window(0,bag,bagWindow,cPage[page],"Box");
         GUI.depth = 0;
     }
 }
 
 function bagWindow(id:int)
 {   
     GUI.BeginGroup(Rect(0,0,34,165));
     if(GUI.Button(Rect(8,20,32,32),"B")){page = 0;}//main inventory for equipments
     if(GUI.Button(Rect(8,55,32,32),"C")){page =1;}//items and consumables
     if(GUI.Button(Rect(8,90,32,32),"D")){page =2;}//quest items and stuff..
     GUI.EndGroup();
 
     switch(page)
     {
        case 0:
             ScrollPosition = GUI.BeginScrollView(Rect(35,20,115,215),ScrollPosition,Rect(0,0,0,430));
             EquipmentGrid();
             GUI.EndScrollView();
             break;
        case 1:
             ScrollPosition = GUI.BeginScrollView(Rect(35,20,115,215),ScrollPosition,Rect(0,0,0,275));
             //ItemGrid(); for consumables function
             GUI.EndScrollView(); 
             break;
        case 2:
             ScrollPosition = GUI.BeginScrollView(Rect(35,20,115,215),ScrollPosition,Rect(0,0,0,275));
             //MiscGrid(); quest items function
             GUI.EndScrollView();
             break;
     }
     GUI.Label(Rect(5,230,120,25),"Gold:");
     GUI.DragWindow();
 }
 function EquipmentGrid()
 {
     for (var i=0;i<itemArray.Length;i++)
     { 
       if(GUI.Button(Rect(0,0+i*(25+2),100,25),GUIContent(itmNm[i],itemArray[i],itmDes[i]),"Box"))
        {
         if((itemArray[i]!= null)&&(Event.current.button == 0)&& toggleRemove == false)
         {
                useItem();
         }
         else if(Event.current.button == 1 && itemArray[i]!= null && toggleRemove ==false)
         {
             toggleRemove = true;
             cString = itmNm[i];
             sString = itmNm[i];
             cmTex = itemArray[i];
             smTex = itemArray[i];
             dcString = itmDes[i];
             dsString = itmDes[i];
             itemArray[i]=null;
             itmNm[i] = null;
             itmDes[i] = null;
         }
         else if((itemArray[i]== null)&&(Event.current.button == 0)&&toggleRemove == true)
         {   
             itemArray[i] = cmTex;
             itmNm[i] = cString;
             itmDes[i] =dcString;
             cmTex = dmTex;
             smTex = null;
             sString = null;
             dcString = null;
             toggleRemove = false;
         }
         else if((itemArray[i]!=null)&&(Event.current.button==0)&&toggleRemove == true)
         {
             smTex = itemArray[i];  //Stored Texture = Texture Array [i]
             itemArray[i] = cmTex;  //Texture Array [i] get current Texture
             cmTex = smTex;        //set current Texture to stored Texture
 
             sString = itmNm[i];    //Stored String = Equipment Description[i]
             itmNm[i] = cString;    //Equipment = current String
             cString = sString;     //current String = stored String
 
             dsString = itmDes[i];
             itmDes[i] = dsString;
             dcString = dsString; 
         }
             Debug.Log(toggleRemove);
        }
      }
 }
 
 function useItem()
 {
     Debug.Log("use functionality in imageArray[i]");
 }
 
 function Togglebag()
 {
     if(toggleBag)
     {
        toggleBag = false;
     }else{
        toggleBag = true;
     }
 }

thanks in advance :D

Comment
Add comment · Show 3
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
avatar image Geine · Oct 10, 2012 at 01:19 AM 0
Share

okay nobody cares...

avatar image Loius · Oct 10, 2012 at 01:31 AM 1
Share

"nobody cares" (quotes because it's false) because it's really hard to read that code. I can't even find where you're trying to display the tooltip. Try showing us just the relevant code ins$$anonymous$$d of the entire thing double-spaced.

avatar image AlucardJay · Oct 10, 2012 at 07:10 AM 0
Share

I just formatted your code (see we do care, or as FN$$anonymous$$ sang "We Care Alot"!), but I agree with Louis, you may want to just post the relevant code portions, as this is still quite a wall of text

=]

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

11 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

Related Questions

need to shorten my code but unsure of how 3 Answers

Issues with Inventory Code (Fixed!!) 0 Answers

Adding Muiltipule GUI.Buttons In an Inventory System Based On Arrays 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Is this considered bad coding 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