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 /
  • Help Room /
avatar image
0
Question by MilesAdamson · Oct 25, 2015 at 05:01 PM · arraytextnew

Help with arrays of arrays please

I am trying to organize all my button texts into a neat array of arrays, I want the below to be put into a 6 element array but I cant get the syntax right.

     public Text[] SwordTexts = new Text[6];
     public Text[] ArmourTexts = new Text[6];
     public Text[] StaffTexts = new Text[6];
     public Text[] RingsTexts = new Text[6];    
     public Text[] AmuletTexts = new Text[6];
     public Text[] CrystalTexts = new Text[6];

Then the array of arrays:

     Text[,] AllTexts = new Text[6, 6];

Then in my start function:

         Text [,] AllTexts = new Text[,]{SwordTexts, ArmourTexts, StaffTexts, RingsTexts, AmuletTexts, CrystalTexts};

This line gets "A nested array initializer was expected" and I don't understand why

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 MilesAdamson · Oct 25, 2015 at 09:01 AM 0
Share

I have also tried

         Text[][] AllTexts = new Text[6][];
 
             Text [][] AllTexts = new Text[][]{SwordTexts, ArmourTexts, StaffTexts, RingsTexts, AmuletTexts, CrystalTexts}
 
             AllTexts[0][0].text = "hi";

And this gives me an object reference not set to an object error

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Statement · Oct 25, 2015 at 09:41 PM

I think you must create the jagged array in Awake. This works.

 using UnityEngine;
 using UnityEngine.UI;
 
 public class Neat : MonoBehaviour
 {
     public Text[] SwordTexts = new Text[6];
     public Text[] ArmourTexts = new Text[6];
     public Text[] StaffTexts = new Text[6];
     public Text[] RingsTexts = new Text[6];
     public Text[] AmuletTexts = new Text[6];
     public Text[] CrystalTexts = new Text[6];
 
     private Text[][] AllTexts;
 
     void Awake()
     {
         AllTexts = new Text[][]
         {
             SwordTexts,
             ArmourTexts,
             StaffTexts,
             RingsTexts,
             AmuletTexts,
             CrystalTexts
         };
     }
 }
Comment
Add comment · Show 1 · 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 MilesAdamson · Oct 26, 2015 at 05:18 PM 0
Share

Thank you!

avatar image
0

Answer by Dinosaurs · Oct 25, 2015 at 09:10 PM

The C# documentation has the format for multidimensional array initializers: https://msdn.microsoft.com/en-us/library/aa664573(v=vs.71).aspx

int[,] b = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {8, 9}};

That format seems like it'll be awkward for your data so I'd probably just set the indices manually:

 Text[,] AllTexts = new Text[6, 6];
 AllTexts[0] = SwordTexts;

etc.

Comment
Add comment · Show 1 · 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 Statement · Oct 25, 2015 at 09:40 PM 0
Share

That produces Error CS0022 Wrong number of indices inside []; expected 2

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Wait For second realtime | Don't work ! 1 Answer

Saving the State of Text in an Array 0 Answers

You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. 0 Answers

Using arrays of vector3s to avoid new 1 Answer

Can I create a GameObject Array then fill UI text elements and then somehow use a For Loop to drop an Array of Int values inside those UI text boxes from largest to lowest? 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