We declared the Character class as public, which means that a Character instance can be created in any other class. Since we have LearningCurve working already, let's declare a new character in the Start() method.
Declare a new Character type variable, called hero, in the Start() method of LearningCurve:
Character hero = new Character();
Let's break this down one step at a time:
- The variable type is specified as Character, meaning that the variable is an instance of that class.
- The variable is named hero, and it is created using the new keyword, followed by the Character class name and two parentheses. This is where the actual instance is created in the program's memory, even if the class is empty right now.Â
We can use the hero variable just like any other object we've worked with so far. When the Character class gets variables and methods of its own, we can access them from hero using...