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 xavierm25 · Jan 18, 2014 at 10:39 PM · list

Best way to add item to other script list?

Here my script named Boxitem:

 import System.Collections.Generic;
 
 var items : Createditems = new Createditems ();
 var BoxList : List.<Items> = new List.<Items>();
 
 function Start () {
 
 BoxList.Add(items.AntirocketItem);
 BoxList.Add(items.WaterItem);
 BoxList.Add(items.AntirocketItem);
 
 
 }
 
 var Boxopen : boolean;
 
 function OnMouseDown () {
 
     Boxopen = !Boxopen;
     
 }
 
 function OnGUI () {
     var w = 250;
     var h = 300;
     var rect = Rect((Screen.width-w)/2, (Screen.height-h)/2, 300, 200);
     
     if(Boxopen){
     GUI.Box (rect , "Box Items");
         for(var x = 0; x < BoxList.Count; x++) {
             if(GUI.Button(Rect(((Screen.width-w)/2) + 5, (((Screen.height-h)/2) + 30) + (30 * x), 290, 30), "Name:  " + BoxList[x].Name + "     Qty:  " + BoxList[x].Qty)) {
                 Debug.Log("Item to add: " + BoxList[x].Itemsname);
                 var additem : ExtractorGUI = gameObject.GetComponent(ExtractorGUI);
                 additem.Itemtoadd = BoxList[x].Itemsname; //here my problem
                 additem.AddItem();  //not work too...
                 BoxList.RemoveAt(x);
                 
             }
         }
     }
 }
 
 function Update () {
     
     if(BoxList.Count <= 0){
     Destroy (gameObject, 1);
     }
 
 }

I create another script for vehicle ExtractorGUI who have his own inventory. and i

Comment
Add comment · Show 18
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 xavierm25 · Jan 18, 2014 at 10:42 PM 0
Share

Sorry my message was cut...

Here ExtractorGUI script

 import System.Collections.Generic;
 
 
 
 var items : Createditems = new Createditems ();
 var InvList : List.<Items> = new List.<Items>();
 var EquipList : List.<Items> = new List.<Items>();
 
 var Itemtoadd : String;
 
 function AddItem () {
 
     InvList.Add(items.Itemtoadd);
     
 }

Witch way would be the best to add BoxList Items to InvList Items?

avatar image getyour411 · Jan 18, 2014 at 10:42 PM 0
Share

What is the ExtractorGUI "Itemtoadd" or "AddItem" method/code? What is the error

avatar image xavierm25 · Jan 18, 2014 at 10:50 PM 0
Share

Thank for your quick answer!!

I use something like : InvList.Add(items.WaterItem); To add items to InvList..

The error is:

NullReferenceException: Object reference not set to an instance of an object BoxItem.OnGUI () (at Assets/Game building/BoxItem/BoxItem.js:25)

I'm not sure what the best way to acheive this task i try many think but the same error appear.

avatar image getyour411 · Jan 18, 2014 at 10:54 PM 0
Share

Your AddItem() function doesn't have an inbound parameter, you need to pass it something so it knows what to add

avatar image xavierm25 · Jan 19, 2014 at 12:24 AM 0
Share

Thank!! i've modified my ExtractorGUI script to:

 import System.Collections.Generic;
 
 
 var items : Createditems = new Createditems ();
 var InvList : List.<Items> = new List.<Items>();
 var EquipList : List.<Items> = new List.<Items>();
 
 function AddItem (Itemtoadd) {
 
     InvList.Add(Itemtoadd);
     
 }

So if i call it on ExtractorGUI it's work very well:

 function Start () {
 
 AddItem(items.WaterItems);    
 
 }

But i still unable to call the fonction on Boxitem

 for(var x = 0; x < BoxList.Count; x++) {
             if(GUI.Button(Rect(((Screen.width-w)/2) + 5, (((Screen.height-h)/2) + 30) + (30 * x), 290, 30), "Name:  " + BoxList[x].Name + "     Qty:  " + BoxList[x].Qty)) {
 
                 var additem : ExtractorGUI = gameObject.GetComponent(ExtractorGUI);
                 var transferitem = BoxList[x];
                 Debug.Log("Item to add: " + transferitem);
                 additem.AddItem(items.transferitem);
                 BoxList.RemoveAt(x);
                 
             }
         }

Think i'm really noob! Sorry...

Show more comments

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

18 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

Related Questions

A node in a childnode? 1 Answer

Master Server Current Games List 1 Answer

The name 'List' does not denote a valid type ('not found')? 1 Answer

Best way to list all active quests in a GUI 1 Answer

Custom list-item name 0 Answers


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