Hey guys, i have started working with Unity several weeks ago. I have some knowledge about OOP and have worked with some languages and platforms before. This is the first time I am working with scripts. I started to watch several tutorials and most of them deliver quite nice and sophisticated informations, but what I’m missing is how to manage my project, which led me to the following problem:
I’m working on a puzzle game. Each level is basicly structured the same way. The only difference is the number of GameObjects and some level-dependend informations, like how many moves the player already made. So beside a GameManager object, that manages comprehensive data and that i wouldn’t allow to get destroyed, i have a LevelManager script. So every level has basicly the same LevelManager script. On top they have a LevelData# which contains the level-dependend informations and adds every GameObject of the current Level(Scene) to a list (which is a field of LevelManager) in the OnAwake method. The thing is, that I’m accessing this list from yet another script in its Update method. Unity throws plenty NullReferenceExceptions, telling me, that the list has no elements in it.
Besides the fact, that i would like to know, why this problem occurs, i moreover want to know, if this approach is ok (since it seems pretty cluttered to me)?! I read articles about Inheritance vs Composition referred to this problem, but this whole workflow with scripts and the unity editor seems not to apply fully to that.
I would really appreciate any kind of help. Maybe you guys have some references for me, that would enlighten me.
Regards