Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 tonyf1121 · Jun 10, 2011 at 02:19 AM · javascriptinventoryinventory system

Inventory Drop Function Problem

Hello All, My name is anthony faraci and im in need of a bit of help...Ive been programing and scripting for 5 almost 6 years, but im having a bit of a problem with my inventory system. I have the inventory itself working and the pick up of items, but i cant seem to figure out how I could drop the items. Here are my Scripts:

This is attached to the Item itself:

 public var InventoryIcon :  Texture2D;
 public var ItemDescription : String;
 public var ItemClass : String;
 public var defence : int;
 public var damage : int;
 
 var doWindow : boolean = false;
 
 function OnMouseOver() {
 doWindow=true;
 }
 function OnMouseExit() {
 doWindow=false;
 }
 
 function OnGUI() {
 
 if (doWindow)
 GUI.Window (0, Rect (110,10,200,80), DoWindow, "Info");
 }
 
 function OnMouseDown() {
     var inv = FindObjectOfType(inv2);
     inv.AddItem( gameObject, InventoryIcon );
     Network.Destroy(this.gameObject);
     Debug.Log("item picked");
 }
 
 function DoWindow (windowID : int) {
     GUI.Label (new Rect(5, 15, 200, 25), "Item:" + ItemDescription);
     GUI.Label (new Rect(5, 30, 90, 25), "Class:" + ItemClass);
     GUI.Label (new Rect(5, 45, 90, 25), "Defence:" + defence);
     GUI.Label (new Rect(5, 60, 90, 25), "Damage:" + damage);
 }

This is Put on the player:

 var inventory : Array;
 
 var doWindow : boolean = false;
 
 
 public var emptyTex : Texture;
 
 
 public var inventorySizeX = 4;
 public var inventorySizeY = 5;
 

 var iconWidthHeight = 40;

 var spacing = 4;
 

 public var offSet = Vector2( 100, 100 );
 

 private var itemImage : Texture2D;
 
 

 class InventoryItem
 {

    var worldObject : GameObject;

    var texRepresentation : Texture2D;
 }
 

 function Awake()
 {
    inventory = new Array(inventorySizeX);
    
     for( var i = 0; i < inventory.length; i ++ )
     {
         inventory[i] = new Array(inventorySizeY);
     }
 }
 
 
 function OnGUI() {
 
    var texToUse : Texture2D;
    var currentInventoryItem : InventoryItem;
 

     for( var i = 0; i < inventory.length; i ++ )
     {

         for( var k = 0; k < inventory[i].length; k ++ )
         {
            texToUse = emptyTex;
            currentInventoryItem = inventory[i][k];
            

             if( inventory[i][k] != null )
             {
                 texToUse = currentInventoryItem.texRepresentation;
             }
            
             var it = GUI.Button( new Rect( offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), texToUse );
             GUI.Button( new Rect( offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), texToUse );
             var w : int = 0;
             var h : int = 0;
             if (it){//&& (inventory[i][k]==!null){
 
                 //This is were the drop item command would go
             }
         }
     }
 }
 
 function AddItem( item : InventoryItem )
 {

     for( var i = 0; i < inventory.length; i ++ )
     {

         for( var k = 0; k < inventory[i].length; k ++ )
         {

            if( inventory[i][k] == null )
             {
                 inventory[i][k] = item;
                 return;
             }
         }
     }   
 }
 
 function AddItem( worldObject : GameObject, texRep : Texture2D )
 {
    var newItem = new InventoryItem();
 
     newItem.worldObject = worldObject;
     newItem.texRepresentation = texRep;
       
    AddItem( newItem );   
 }


Any help would be much appreciated!

Comment
Add comment · Show 1
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 petroz.du · Jun 10, 2011 at 04:23 AM 0
Share

tl;dr. You would do better to explain the problem, and how you have attempted to solve it in words or pseudocode, rather than posting a wall of code. I did skim your code and from what I can see it seems you want to drop items when you update the GUI, that seems incorrect.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by slkjdfv · Jun 10, 2011 at 05:17 AM

If you'd look at the showcase forum there are better inventory systems that have item pickup and dropping. try this system out i made it myself and its very easy to use http://forum.unity3d.com/threads/90871-advanced-inventory-system-example

Comment
Add comment · Share
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to optimize this script and add items imediately without grids 0 Answers

Having scripts interact 1 Answer

Inventory code not working [JS] 0 Answers

Is this considered bad coding 1 Answer

How to display textures that are in an array? 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