Issue after conversion from Javascript to C#

Hello, after following a tutorial in Javascript about the use of GUI class and such, I decided to translate the code to C# since the tutorial doesn’t provide it.

My issue is with 4 variables of an Item class defined in the Menu.js/Menu.cs file

public var a_weapons : Item[];
public var a_armors : Item[]; 
public var a_accessories : Item[];
public var a_items : Item[];

In Javascript, they display perfectly in Unity’s Inspector after assigned to a gameobject, but that’s not the case with C#.:

public Item[] a_weapons;
public Item[] a_armors;
public Item[] a_accessories;
public Item[] a_items;

I have attached both files for further inspection, any help would be appreciated.

898784–33573–$Menux.cs (11.1 KB)
898784–33574–$Menu.js (11.5 KB)

I put the Item class in a separate file and let it inherit from MonoBehaviour. Then it works.

I dont know why it is like that, maybe someone else can explain.

Thanks for the reply, I tested on a new empty project; only the scripts and a GameObject to test on.

With Menu and Item as separate files, and inheriting from MonoBehaviour, all the public variables are visible in the inspector, but changing the size of the Item array variables gives unusable elements.

C#:

Javascript:

You must mark your Item class as serializeable

[System.Serializable]
public class Item : MonoBehaviour {

}

That’s because Unity can only serialize classes which Inhert from Component (Or UnityEngine.Object not sure)

Thanks, it’s all working now.

Also tested it without inheriting from MonoBehaviour out of curiosity (like it’s displayed in the Scripting Reference) and it seemed to work still.

But this doesn’t work

public class Item {
}

public class Blah : MonoBehaviour {
    public class Item;
}

This won’t show in the Inspector, because you can not assign non Components to a variable via Inspector.

UnityEngine.ScriptableObject I believe. You may also have to mark your fields as Serializable.