This actually works perfectly fine right now and adds as many items as I want. I’m relatively new to C# but shouldn’t levelobject be an array or a list or something? Or does Unity take care of this in the background for me?
As an additional test, I’ve parented every object to a single other object (world) and when I Destroyed world, it deleted all the other objects I created.
So, should I do this a better way (list of GameObjects) or is the above actually OK?
(levelobject is defined as just GameObject levelobject elsewhere in the file)
Reason: if you have some other kind of asset (Texture or Material for instance) named exactly the same, it is a 50/50 chance which one Unity will load, since Resources.Load() does NOT accept the file extension. If it tries to load foobar.png instead of foobar.prefab, it will fail 100% of the time. Specifying the is the only way to make sure it goes after the prefab.
As a case of style, you should CamelCase your functions, and you should stay away from using identifiers that are already in use inside the MonoBehavior, in this case name.
Reason: when you ask for help, your code is immediately more readable and less likely to have weird problems from hiding existing identifiers. For instance, if you tried to access the name field of the UnityEngine.Object in this method, you would not get it unless you explicitly wrote this.name, and that could be very confusing.
Hey, thank you for the tips! I really appreciate it and I’m going to implement them. It’s especially easy now since I’m still very early in the project.