- Home /
Arrays don't show up on inspector
I have these two classes and both of them don't show up the arrays on inspector. Does someone can help me out why?
public class TowerSystemManager : MonoBehaviour { public LevelTowerSystemController[] towerType = new LevelTowerSystemController[ 4 ]; }
[System.Serializable]
public class LevelTowerSystemController : MonoBehaviour
{
public GameObject[] towerLevel = new GameObject[ 2 ];
public GameObject this[ int i ]
{
get
{
return towerLevel[ i ];
}
set
{
towerLevel[ i ] = value;
}
}
public int Length
{
get
{
return towerLevel.Length;
}
}
}
$$anonymous$$aybe start with something simpler? $$anonymous$$onobehavior scripts just show up in the Inspector for the object. They wouldn't be in an array -- they're the whole component. You also wouldn't normally need to put [sys.serialize] in front of them.
towerLevel should be appearing as an array. But you don't normally assign (`new`) anything to a public array (I don't think what you have is even legal.) You set the size and items directly in the Inspectors.
And, those getters and setters ... they don't do anything except impress hard-core Java-ists. If they're giving you the slightest trouble, get rid of them.
Assu$$anonymous$$g that your script is "TowerSystem$$anonymous$$anager.cs" and not "LevelTowerSystemController.cs," I would make LevelTowerSystemController
its own class rather than a child class of $$anonymous$$onobehaviour
(though this might not be the issue).
I don't think having two classes extending $$anonymous$$onobehaviour
in the same script file is a good idea.
Answer by game-dev333 · Jul 20, 2015 at 06:26 AM
Create two different scripts 1)TowerSystemManager.cs
using UnityEngine;
using System.Collections;
public class TowerSystemManager : MonoBehaviour
{
public LevelTowerSystemController[] towerType;
}
2) LevelTowerSystemController.cs
using UnityEngine;
using System.Collections;
[System.Serializable]
public class LevelTowerSystemController : TowerSystemManager{
public GameObject[] towerLevel = new GameObject[ 2 ];
public GameObject this [int i] {
get {
return towerLevel [i];
}
set {
towerLevel [i] = value;
}
}
public int Length {
get {
return towerLevel.Length;
}
}
}
showed me this on inspector
Your answer
![](https://koobas.hobune.stream/wayback/20220611232053im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Renaming Inspector 2D Array Element 0 , Element 1 1 Answer
See MonoScript's attributes in the inspector (when it is in an array) 0 Answers
How to change the way the inspector shows variables Javascript 1 Answer
Displaying public variables in the inspector 2 Answers
Keep values in inspector while changing variable name 2 Answers