I get this error though. NullReferenceException: Object reference not set to an instance of an object (wrapper stelemref) object:stelemref (object,intptr,object)
Arrays indices start at 0, not 1, so that’s going to cause an error when you get up to checking #48. It fails before that right now though, because you haven’t actually initialized the chestRend array yet. You need to say:
private Renderer[] chestRend = new Renderer[chestSensors.length];
or just initialize it directly to 48 if you know for certain there are, and always will be, exactly 48 objects with the tag “chestSensors”.
You can also skip all of this if the Renderers are on child objects of the current object. You can then just call GetComponentsInChildren() to get an array of all of the renderers directly (this WILL include the Renderer on the current object as well, if one exists, so be wary of that).
Nope, it doesn’t use the name for organizational purposes at all- it’ll likely load them by their internal ID numbers, but it doesn’t matter. Most of the time the “name” of a GameObject is completely meaningless beyond a means of making visual organization easier in the scene (for you, not the program). If you want them sorted (and since you’re using GameObjects and not ints or some other very small value type), it would be better in the long-run if you made the array into a List and then just ran the Sort function to organize it by name.
If you’re adamant about leaving it as a array, you can run “System.Array.Sort(arrayName);” instead.
EDIT: Skimmed over it and missed the OrderBy() completely, lol.
“.enabled” is deprecated, you need to use “.SetActive()” instead. This is still referring to the chestRender array, not the chestSensors array, so that change is irrelevant. Also, wasn’t this called “chestRend” in a previous post? Don’t give me snippets if you’re having problems though, please post the whole thing.
Name is a string, so it gets sorted alphabetically. You could parse the name to an int (bad idea in the long run). Or you could add a variable to a script that is a sorting ID and use that.