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 /
This question was closed Dec 12, 2014 at 03:44 AM by Kiwasi for the following reason:

Duplicate Question

avatar image
-2
Question by JoshMBeyer · Dec 12, 2014 at 01:38 AM · c#listaccess

How to access List<> from other script?

I have a list where each item has 4 properties. Basicly I want a long long long list of these items. and beable to grab them from another script. So the ActionScript, and the ListScript. How can I access them?

  List<Item> anItem = new List<Item>();

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 Kiwasi · Dec 12, 2014 at 03:46 AM 0
Share

Search UA. This has been answered hundreds of times.

1 Reply

  • Sort: 
avatar image
-1

Answer by zaid87 · Dec 12, 2014 at 01:49 AM

Simplest way I can think of is to set them to "public static" so

 public static List<Item> anItem = new List<Item>();

and to get the list just do

 ClassName.anItem;

Although, this means that the List will be static. So even if you have multiple instances of the class, the value in the List will be shared.

Comment
Add comment · Show 4 · 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
avatar image JoshMBeyer · Dec 12, 2014 at 01:54 AM 0
Share

well I mean there are literally 1000's of items in this list on script 2. Script 1 has to gather 1 item from script 1's list and display it. Then also display all 4 properties(Subclasses) of that item aswell. and this happens once for every item in the list when the time is right it will switch to the next item. I have no clue how to do this everything i try is incorrect

avatar image JoshMBeyer · Dec 12, 2014 at 01:55 AM 0
Share

I already have it working on 1 single script.. but the list will be so long i don't want to place it all in the same script as the code of the gameplay

avatar image zaid87 · Dec 12, 2014 at 02:20 AM 0
Share

Sorry, not sure if I understand..... Is script2 attached to any Game Object? If not, then you can just create a normal class with that list in it. Then create an instance of that class in script1 (no need to make the list static) so that script1 can access it. And what do you mean by 4 properties? Like Name, Count, Price, etc, like that? If yes, then in script1 just do

instanceName.anItem[999].Name

avatar image JoshMBeyer · Dec 12, 2014 at 02:41 AM 0
Share

Here is my full explanation of what i need to figure out. http://answers.unity3d.com/questions/852717/last-time-ill-ask-for-help-on-this-lol.html

Follow this Question

Answers Answers and Comments

28 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Last time I'll ask for help on this lol 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How Do I Access and Change Items in a List on Another Script? 2 Answers

A node in a childnode? 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