• 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 /
  • Help Room /
avatar image
0
Question by Mike-Brink · Jan 27, 2016 at 11:12 AM · arrayslists

Problems with adding an array to a list

I have tried to use a list for storing some string arrays, however, each time I add a new element to it, all previous elements are replaced by the new one. I have searched everywhere, but can't seem to find an answer to my problem. I hope you can help me. The code looks as follows:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;
 
 public class FavoriteTracks : MonoBehaviour {
     public List<string> Titles;
     public List<string> Links;
     public List<string[]> MultiLinks; //This is the one, I have problems with
     public List<Sprite> Icons;
     public List<bool> BuiltOrNot;
     public int count;
     private int multicount = 0;
     private bool isTrue;
 
     void Awake()
     {
         MultiLinks = new List<string[]>();
         
     }
 
     public void ButtonAdd(string name, string link, Sprite icon, bool multiornot)
     {
         //This one works fine
         Titles.Add(name);
         Links.Add(link);
         Icons.Add(icon);
         BuiltOrNot.Add(multiornot);
         count++;
     }
     public void ButtonAdd(string name, string[] link, Sprite icon, bool multiornot)
     {
         //Here I add the string arrays, and have problems
         Titles.Add(name);        
         MultiLinks.Add(link);
         Icons.Add(icon);
         BuiltOrNot.Add(multiornot);
         count++;
         multicount++;
         Debug.Log(MultiLinks[0][0]);
         if (multicount >= 2)
         {
             Debug.Log(MultiLinks[1][0]);
         }
         if (multicount >= 3)
         {            
             Debug.Log(MultiLinks[2][0]);
         }
     }

It is probably not the most efficient way of doing things, but it is what I have for now. All other lists in my script work just fine. It is only the array one that gives me problems.

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 ShadyProductions · Jan 27, 2016 at 11:29 AM 0
Share

Use AddRange ins$$anonymous$$d.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

Remembering list of camera positions is not working 0 Answers

Merging multiple array's from a specific class without manually targeting them 0 Answers

Project transfer Win to Mac list SystemGeneric.Collections issue 0 Answers

How to store objects and then call them? 1 Answer

Find the closest Enemy that has a tag added in a list? 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