Search Unity

Difference between a class inside Main class, class outside Main class, and class as Main class?

Discussion in 'Scripting' started by unity_94d33m, Mar 25, 2019.

  1. unity_94d33m

    unity_94d33m

    Joined:
    Sep 11, 2018
    Posts:
    20
    Here is the pic,
    https://imgur.com/a/ZyobdG1
    Is there a difference between a class inside the Main class, that same class outside the Main class, and that same class as the Main class itself?
     
  2. the_mr_matt

    the_mr_matt

    Joined:
    Jul 21, 2015
    Posts:
    124
    Usually you would nest a class inside another to restrict the scope. If you want Count to only be accessible within BoardManager you could make it private/protected inside BoardManager. I also nest my classes/structs sometimes to organize my data, or if I'm too lazy to make a new file.

    The last two images you shared are exactly the same. It actually doesn't matter if they are in the same or separate cs script files (though it's generally best practice to have them in separate files).
     
    Rafarel and unity_94d33m like this.