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 Siloaman · Jan 07, 2016 at 11:10 PM · list of lists

Working with Lists in Unity3d

I am looking for help working with List<> and I am hoping that somebody can give a short explanation of all the points that I am asking.


a) In the tutorials online, I keep seeing how to initialize a new List, such as:

List< int > Level = new List< int >();

However, I don't see an explanation for a List<> declaration (assuming I created a List<> on my character script beforehand and want to continue using data I saved earlier). It appears to me that initializing a new List would effective create something new, not continue the data I saved earlier. How would I bring back my data from a previous instance of my game inside a List variable???


b) During game testing with Scene and Console how do I used Debug.Log to show all the saved data I have in my List variable??? Or simply, how can I view all the data inside my List in the editor if I make it a public variable??


c) Let's say I want to create a List that holds 2 pieces of information, like

(Player Level) and (ExperiencePointsToNextLevel)...

Do I have to make both of them int variables or can I have one float and one int variable??? How would I declare something like that??

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 LessThanEpic · Jan 07, 2016 at 11:20 PM 0
Share

It doesn't sound like you understand what a List is. A List is a type defined by C# and it can only hold one type of data, so you have to pick if you want it to hold ints or floats. To do something like you're talking about with PlayerLevel and ExperiencePointsToNextLevel you probably want to use a struct or a class.

avatar image gjf LessThanEpic · Jan 07, 2016 at 11:30 PM 0
Share

your comment is slightly contradictory - there's no picking ints or floats - the List can be some struct/class...as you state ;)

avatar image vintar · Jan 08, 2016 at 06:17 AM 0
Share

a) How would I bring back my data from a previous instance of my game inside a List variable???

You cant, you would hav to loop through the list and save it in playerprefs for example, then read them back into the list.

b)During game testing with Scene and Console how do I used Debug.Log to show all the saved data I have in my List variable??? Or simply, how can I view all the data inside my List in the editor if I make it a public variable??

Assu$$anonymous$$g it is a public list, while in-game, go into scene view, click on the object and look in the inspector, the list will be there.

c)Do I have to make both of them int variables or can I have one float and one int variable??? How would I declare something like that??

you could do something like this :

 [System.Serializable]
     public class PlayerData
     {
            public int Level = 0;
            public float PointToNExtLevel = 0;
     }
     
     public class Player : $$anonymous$$onobehaviour
     {
         public List<PlayerData> Data;
     }
 

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SunnyChow · Jan 08, 2016 at 01:54 AM

a)

I am not sure what you mean

If you want all objects share one list, you can make it static.

 static List< int > Level = new List< int >();

b) you need a for-loop

 string result = "";
 for(int i = 0 ; i< Level.Count;i++){
 result +=Level[i]+",";
 }
 Debug.Log(result);

c) I suggest you not to use List

 int level;
 float exp4nextLevel;

or you can use Hashtable, but you will have to remember the type and purpose of each value by yourself, which is not very convenient.

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

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

Related Questions

Does Unity support lists of lists? 0 Answers

Checking a list containing another list, and checking if the elements in the list are equal problem 1 Answer

stack by quanity...? C# 2 Answers

List Sorting But Random Order 2 Answers

Trying to make a hacking minigame... 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