Have some class!
To start building Robot Repair, we need to write a custom class in our GameScript script. We've already seen some built-in Unity classes in the previous chapter: the Renderer
class, the Input
class, and so on. We're going to create our own class called Card
. You guessed it, the Card
class is going to represent the cards in the game.
Double-click to open the GameScript script.
Add the following code to the script, beneath (and outside) the
Update
function:class Card extends System.Object { var isFaceUp:boolean = false; var isMatched:boolean = false; var img:String; function Card() { img = "robot"; } }
Just like the keyword var
declares a variable, we use the keyword class
to declare a class. Next comes the name of our class, Card
. Finally, our Card
class extends System.Object
, which means that it inherits all of its stuff from the built-in System.Object
class much the same way I inherited my fabulous good looks and my withered left knee that smells like...