TuttiFruity arrays in C#?

hey guys,

well ive been having issues with c# arrays.

please bare with me since i am still noob at coding so will appreciate any help you can provide.

using UnityEngine;
using System.Collections;

public class ArrayInfo : MonoBehaviour {

    public object Item = new object[] { "Name",0,"Desc" };

and

using UnityEngine;
using System.Collections;

public class Menu : MonoBehaviour {

    public string[] itemName;
    public float[] itemHP;
    public string[] itemDesc; 
 
    public void OnGUI () { 
 
 
            GUI.skin = MySkin;

            GUI.Label (new Rect (25, 61, 150, 25), itemName[0]);
            GUI.Label (new Rect (25, 90, 150, 25), itemHP.ToString()[0]);
            GUI.Label (new Rect (25, 122, 150, 25), itemDesc[0]);
 
 
 
                    ArrayInfo = GameObject.Find("ArrayInfoGO").GetComponent("ArrayInfo") as ArrayInfo;

                    ArrayInfo.Item[0] = itemName[0];
                    ArrayInfo.Item[1] = itemHP[0];
                    ArrayInfo.Item[2] = itemDesc[0];
                 
    }

but i am getting compiler errors
Assets/Scripts/Menu.cs(150,54): error CS0021: Cannot apply indexing with [ ] to an expression of type `object’

which is this line:

any suggestion on what am i doing wrong,

it should be a simple thing which i am missing since i may be tired and looking at the wrong place. :frowning:

anyways, your help will be greatly appreciated.

regards

public object Item = new object[] { "Name",0,"Desc" };

This line is missing the square brackets next to object. It should be:

public object[] Item = new object[] { "Name",0,"Desc" };

great finding,

how could i missed that one.

i told ya, maybe i am too tired tonight.

thanks bro, you saved me of more hours of hair pulling, lol

thanks again

I remember my first time forgetting the brackets on a array :roll_eyes:

As a side note you should opt to utilize generic C# functions over the old string parameter get component. I also would recommend against holding an array of objects. You should be able to reduce this array, and if you can’t it’s generally because of poor design or lack of OOP principles, to an array of common types.

It seems as if your object array represents data that could be encapsulated by some sort of item object. You should write an item class instead of storing this information in a random object[ ].