how do i access a gameobject inside a class that is inside the monobehavior class

i have looked up how to do this online and couldnt find any help

One way is to pass a reference to the Monobehavior (or even the GameObject if you want) into the inner class at construction time.

1 Like

This is that kind of problem what looks easy but is really comples. It have multiple solutions. You can pass it as constructor argument as Kurt-Dekker suggested. Not that this solution is bad. But this makes you not able to construc that class instances without particular game object or monobehaviour. You can make it property and set it later, but this forces you to write more than one lines of code to properly construct the instance and moreover, it forces anyone who use that class to know what it needs to be used - the same monobehavior ang game object existance requirement is moved one level up in yuour program, but it still here. You might want to use dependecy injection framework to avoid this, but it forces you to stick to some weird framework with its limitations. The choice is up to you. I prefer to reference outer class from inner and let inner class to decide what he wants, but it is just first option reversed.