Wizard Coding

So when I finished coding I was unable to put: int guess = (max + min) / 2;
so I ended up putting it in each brackets (Start and Update).
I am asking why was Unity putting an error when I tried to put it outside of those brackets?

Hi Ano_Dude,

Welcome to our community! :slight_smile:

In C#, we cannot calculate or access anything at class level because the other fields might not have been initialised yet when you try to use them. That’s why we must do things in methods. When methods get called, the entire object including its content definitely exists. That’s how C# works.

Did this clear it up for you?


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms