Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

MultiDimensional Array of TextMeshProUGUI

Discussion in 'Scripting' started by ScamTheMan, Jul 3, 2020.

  1. ScamTheMan

    ScamTheMan

    Joined:
    Oct 4, 2018
    Posts:
    48
    Hello, is it possible to make public multidimensional array of TextMeshProUGUI objects?
    I tried using two possibilities but none of them work
    Code (CSharp):
    1. public TextMeshProUGUI[,] Array = new TextMeshProUGUI[9,9];
    2. public TextMeshProUGUI[][] Array = new TextMeshProUGUI[9][9];
    3.  
    The problem is that everytime I make this multidimensional array, it dissappears from Inspector so I am not able to attach objects to it.
    Is it even possible? If not, is there a way to call one of the array by integer?
    e.g.
    Code (CSharp):
    1. for (int i = 0; i <= 8; i++)
    2.         {
    3.             for (int x = 0; x <= 8; x++)
    4.             {
    5.                 Array[i, x].text = "Hello";
    6.             }
    7.         }
     
  2. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    162
    try this

    Code (CSharp):
    1.    
    2.  
    3. [Serializable]
    4.     public class ArrayDimensionY
    5.     {
    6. public TextMeshProUGUI tmField;
    7.     }
    8.  
    9.     [Serializable]
    10.     public class ArrayDimensionX
    11.     {
    12.         public ArrayDimensionY[] ady;
    13.     }
    14.  
    15.  
    16.     public ArrayDimensionX[] adx;
    17.  
    18.  
     
  3. ScamTheMan

    ScamTheMan

    Joined:
    Oct 4, 2018
    Posts:
    48
    Thank you, it works.
     
    raarc likes this.
unityunity