In the example above, Window is the class. Each class will have a constructor, in C# the constructor is a method of the same name as the class, so;
public Window(int x, int y)
{
// ...
}
is the constructor for the Window class. In order to create an instance of the Window object you use the new keyword.
Window a
is defining a variable named a
of type Window
. It is then initialised with a new instance of the Window class.
In Unity however, if your classes are inheriting from MonoBehaviour you do not do this, but you can if your classes do not inherit from MonoBehaviour.
As an example, I may have a Player class which retains some data about the Player, but because I don’t need to use any of the Unity functionality, I do not inherit from MonoBehaviour. A script attached to a GameObject in the scene might use;
private void Start()
{
Player player = new Player();
}
This would intialise the player variable to represent a new instance of the Player class (object).
Hope this helps ![:slight_smile: :slight_smile:](https://sjc3.discourse-cdn.com/business5/images/emoji/twitter/slight_smile.png?v=5)