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.

  1. Double-click to open the GameScript script.
  2. 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, ...

Get Unity 4.x Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.