- Home /
Duplicate Question
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>();
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.
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
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
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
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
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