Unity 3D Game Development by Example

Discussion in 'Teaching' started by UntoldEnt, Sep 24, 2010.

  1. UntoldEnt

    UntoldEnt

    New Member

    Joined:
    May 5, 2009
    Messages:
    10
    Hi, everyone! I just wanted to start a thread for those of you reading Unity 3D Game Development by Example, a book I just finished writing with Packt Publishing, the same folks who published Will Goldstone's Unity Game Development Essentials.

    [​IMG]

    Here's a link to the book:

    http://bit.ly/benbHv

    And here's a link to a quick FAQ and chapter list on my blog:

    http://bit.ly/b3VzpB

    I wrote the book with beginners in mind - not just Unity beginners, but game development beginners. I had lots of friends saying "I've heard of Unity ... I'd like to check it out." I'd say "Have you ever done any programming?" and they'd say "No." So they'd be able to use this book and be successful.

    I'm using the book as the study guide for a college-level 3D programming intro course, which is going very well.

    The first two chapters are theoretical, and drive home the need to start simply with a small, manageable project; the remaining ten chapters help the reader develop four very simple casual-style games:

    - a keep-up game (3D)
    - a catch game (2.5D)
    - a memory card game (2D - entirely using Unity GUI)
    - a very basic space shooter (2.5D)

    The book came hot off the printing presses today! As soon as Packt gives the thumbs-up, they'll start printing copies. It's also available as an e-book.

    I'm really looking forward to hearing your feedback! Throw me your email and I'll drop you a line when the book is out, which will be very soon.

    - Ryan

    ryan {the at sign} untoldentertainment {the dot sign} com
  2. Esila

    Esila

    New Member

    Joined:
    Mar 22, 2009
    Messages:
    106
    I have already bought your book from packtpub.com, but it is in pre-order. When can be download???
  3. UntoldEnt

    UntoldEnt

    New Member

    Joined:
    May 5, 2009
    Messages:
    10
    Thanks so much, Esila!

    The publisher just received the first hard copy today. They'll check it over and give the thumbs-up to the printers. Once the hard copy's rolling off the presses, they'll make the e-book version available.

    We've been calling this a September book, so i expect it to be ready next week. Thanks for your patience!

    - Ryan
  4. TheLorax

    TheLorax

    Member

    Joined:
    Mar 25, 2007
    Messages:
    82
    Hello! I just bought the eBook/Book combo earlier this evening. I've read through the first two chapters and I like that you're stressing the start small, be successful, and grow into bigger things approach. I too see many people say that they're going to make the next WoW and when they hit the first snag, quit. Quit to become an accountant of all things!!!

    Thanks for taking the time to do this, and I'll write more as I get through it!

    TheLorax
  5. rawi

    rawi

    New Member

    Joined:
    Jul 28, 2005
    Messages:
    19
    Hi Ryan, i bought the combo yesterday, hardcover will take a while i suppose, but ebook is on my desktop!
    first impression: really nice and helpful for the beginner.
    I always appreciate learning materials with small, but full starting projects - which seem to be fulfilled in your book.
    I am excited to work with the lessons !

    one flaw though - especially for non-native english speakers!
    the language, the slang expression are sometimes hard to understand ( 'tis volley, no grabsies, nix the referee, cube-fest)
    I suppose, for english ears that sounds cool!

    Besides that, your book is a wonderful learning tool with a thorough introduction and a detailed guidance!

    thanks so much for that!

    rawi
  6. Mani

    Mani

    New Member

    Joined:
    Jan 12, 2009
    Messages:
    117
    Congrats on the book Ryan! I heard that it was great!
  7. eedok

    eedok

    Member

    Joined:
    Sep 21, 2009
    Messages:
    179
    Just a bit of background, I'm a flash programmer at XGen, and I came across this part of the book:
    [​IMG]
    The last 2 bullet points are already in Motherload, you just have to dig deeper :p

    You totally owe us a sale of Super Motherload when it hits Wiiware for this inaccuracy :p
  8. UntoldEnt

    UntoldEnt

    New Member

    Joined:
    May 5, 2009
    Messages:
    10
    i'll grant you the first point. On the second, i was trying to avoid doling out spoilers.

    i'll be careful not to freely publicize your games in my books in the future. ;)

    - Ryan
  9. Esila

    Esila

    New Member

    Joined:
    Mar 22, 2009
    Messages:
    106
    I am downloading your ebook from packtpub.com.
    Happy~~~
  10. tim_bkk

    tim_bkk

    New Member

    Joined:
    Sep 22, 2010
    Messages:
    7
    Just bought the book a few days ago and read a few chapters. I think it will be a great intro for designers without any programming experience.

    As an experienced programmer, with moderate Unity experience, this book is clearly not for me though.
  11. Merries

    Merries

    New Member

    Joined:
    Feb 2, 2009
    Messages:
    244
    It is a very good book for a beginner, and I'm learning alot, it is very well written and easy to understand, thank you!
  12. Merries

    Merries

    New Member

    Joined:
    Feb 2, 2009
    Messages:
    244
    I am kinda stuck Game 2 Robot Repair with the GUI Game Start button. I see the title screen but the button is not showing. Below is the provided code.

    var customSkin:GUISkin;

    function OnGUI() {
    //Button width:
    var buttonW:int = 100;
    //Button height:
    var buttonH:int = 50;
    //Half of the screen width:
    var halfScreenW:float=Screen.width/2;
    //Half of the button width:
    var halfButtonW:float = buttonW/2;

    GUI.skin = customSkin;
    if(GUI.Button(Rect(halfScreenW-halfButtonW,560,buttonW,buttonH),"PlayGame"))
    {
    print("You Clicked Me!");
    }
    }

    Could the title screen be hiding the GUI button? Thank you.
  13. Merries

    Merries

    New Member

    Joined:
    Feb 2, 2009
    Messages:
    244
    I figured this out in the following:

    GUI.skin = customSkin;
    if(GUI.Button(Rect(halfScreenW-halfButtonW,560,buttonW,buttonH),"PlayGame"))

    I changed the number 560 to 400 and it can be seen and fits nicely.
  14. ployer

    ployer

    New Member

    Joined:
    Jul 28, 2009
    Messages:
    28
    I have been wanting to get into Unity for a bit now, however I like a book to lead me along paths. I purchased this book last night after reading the thoughts on it in this thread and I must agree it is a well written book. My only gripe (and this is really just a matter of personal preference) is that I wish the code samples were in C# as that is the language I used daily in my professional life and I am well versed in it. I was however able to translate most of it to C# with out much issue but there was a time or two it wasn't super clear.So far I am about half way through chapter 4 and I have understood everything completely, while a lot of books on various topics I've come across over the years tend to gloss over things you tend to explain them pretty well. Once I finish the book I'll come back I'm sure and make a few more comments, but my initials thoughts are it is a job very well done.

    Phil
  15. DocSWAB

    DocSWAB

    New Member

    Joined:
    Aug 28, 2006
    Messages:
    615
    Great to see some books about using Unity to extend the documentation and community resources.

    Do you and Will have plans for 2nd editions updated for 3.0?
  16. UntoldEnt

    UntoldEnt

    New Member

    Joined:
    May 5, 2009
    Messages:
    10
    Will left a comment on my blog when i announced that Unity 3D Game Development by Example was available for pre-order:

    Keep in mind that Will wrote his book a year ago. i just finished mine, so the thought of diving into a second edition right now makes me feel a bit barfy. i'd like to wait to see how the book is received, so that i can decide 1) whether people even WANT a second edition and 2) what should be in it.
  17. Hakimo

    Hakimo

    Member

    Joined:
    Apr 29, 2010
    Messages:
    316
    Nice, can't wait to see the book in local stores :)
  18. Dantes

    Dantes

    New Member

    Joined:
    Sep 30, 2010
    Messages:
    6
    Well being a COMPLETE Unity newbie, I went ahead and ordered your book, Ryan. I actually got the combo pack with Will's book which basically made one book free!. I can't wait to dive into it and start my journey. I understand the whole issue with 3.0 but what you stated below makes complete sense to me.

    Best of luck on the book's popularity!
  19. DocSWAB

    DocSWAB

    New Member

    Joined:
    Aug 28, 2006
    Messages:
    615
    The reason I would love to see 3.0 based 2nd editions of these books is that there have been a number of API changes as well as significant new workflows (lightmapping, for example), and sorting out what's new and what's old, for both newcomers and more experienced users alike is challenging.
  20. minevr

    minevr

    New Member

    Joined:
    Mar 4, 2008
    Messages:
    1,009
    Looks great! I would like to have it
  21. Wickedsunny

    Wickedsunny

    New Member

    Joined:
    Oct 12, 2010
    Messages:
    51
  22. Ecoe

    Ecoe

    New Member

    Joined:
    Oct 24, 2010
    Messages:
    2
    I bought the book recently have have slowly been going through it. It has been amazingly helpful in finding my way around unity.

    Inside of it it mentions that the projects are already built and available at packtub (chapter 8 description). Packt only seems to have the assets available for download though and not the code itself. Was wondering if anyone could direct me to where these files are?
  23. UntoldEnt

    UntoldEnt

    New Member

    Joined:
    May 5, 2009
    Messages:
    10
    Ecoe - sorry for the delay. These files didn't get uploaded when the book was published, but i'm working hard to make sure they're available this week.

    - Ryan
  24. adminsmithee

    adminsmithee

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    30
    Hey Ryan,

    Thanks for the great book, i bought it sunday and i hope it will get me some programmer moves (i'm a graphical (3D) desinger)
    I followed the steps in youre book (not really getting "it" though, i hope it will sink in soon, Would be a whole bunch easier if it was in dutch ) but im stuck in chapter 5.

    I neatly typed the code but nothing is happening, i guess its due the fact i use a dual monitor set-up but i could also be about complety different (maybe earth rays interfer with my script)

    here is my script:
    It didnt give any compiler errors so im not sure whats going on. (and i get a lot of compiling error because of me Speeling and the wrong UsE of Capitals, dyslected poor me:( )

    <script>
    var cols : int = 4; //the number of colums in the card grid
    var rows : int= 4;// the number of rows in the card grid
    var totalCards : int = cols*rows; //total of cards (16)
    var matchesNeededToWin : int = totalCards * 0.5; // 8 pairs (16/2)
    var matchesMade : int = 0; // at the outset the Pl1 has no matches found
    var cardW : int = 100;
    var cardH : int = 100;
    var aCards : Array; // we'll store all the cards we create in this array
    var aGrid : Array; // This array will keep track of the shuffled, dealt cards
    var aCardsFlipped : ArrayList; //this array will store the two cards that the pl1 flips over
    var playerCanClick : boolean; // we'll use this flag to prevent the player from clicking buttons when we dont want him to
    var playerHasWon : boolean = false; // Store whether or not the player has won, int false

    function Start()
    {
    playerCanClick = true; // we should let the player play
    // initialize the arrays as emty lists:
    aCards = new Array();
    aGrid = new Array();
    aCardsFlipped = new ArrayList ();

    for (i=0; i<rows; i++)
    {
    aGrid = new Array(); //create a new array at index i

    for (j=0; j<cols; j++)
    {
    aGrid [j] = new Card();
    }
    }
    }

    function Update () {
    }

    class Card extends System.Object
    {
    var isFaceUp:boolean = false;
    var isMatched:boolean = false;
    var img:String;

    function Card()
    {
    img = "robot";
    }

    }

    function onGUI ()
    {
    GUILayout.BeginArea (Rect (0,0,Screen.width,Screen.height /3));
    BuildGrid () ;
    BuildGrid () ;
    GUILayout.EndArea();
    print ("building grid!");
    }


    function BuildGrid()
    {
    GUILayout.BeginVertical();
    for(i=0; i<rows; i++)
    {
    GUILayout.BeginHorizontal();
    for(j=0; j<cols; j++)
    {
    var card:Object = aGrid[j];
    if(GUILayout.Button(Resources.Load(card.img),
    GUILayout.Width(cardW)))
    {
    Debug.Log(card.img);
    }
    }
    GUILayout.EndHorizontal();
    }
    GUILayout.EndVertical();
    }
    </script>

    Any enlightment would be vey much apriacated!

    Thnx,
    AAlan
  25. Ecoe

    Ecoe

    New Member

    Joined:
    Oct 24, 2010
    Messages:
    2
    Thank you for the update Untold.

    adminsmithee, quick thing that I noticed in your script that is causing it to draw nothing is you didn't capitalize OnGUI. You also call build grid twice.
  26. adminsmithee

    adminsmithee

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    30
    Thanks Ecoe,

    I changed the script as you suggested, but still no cake :(
    When i digged a little deeper i couldn't find anything wrong.
    I suddenly had a epiphany and attached the script to the camera and that did the trick :)

    hurray, one step closer to build a ultimate WOW (mine will have jet fighters and dragons as well as giant robots with laser vision) :)

    thanks for the help!
  27. sonicviz

    sonicviz

    Member

    Joined:
    May 19, 2009
    Messages:
    844
    Edited/Solved...simple typo!
  28. anothervenue

    anothervenue

    New Member

    Joined:
    Apr 30, 2010
    Messages:
    102
    I am wondering if this is similar to Will Goldstones book, or if its the next level? I devoured Unity Game Development Essentials in less than a week.

    Should I get this book or just go out on my own?
  29. RoyS

    RoyS

    New Member

    Joined:
    Jan 12, 2009
    Messages:
    543
    What is "a keep-up game"? That's the first one on your list for 3D category of game.
    Last edited: Nov 1, 2010
  30. Krodil

    Krodil

    New Member

    Joined:
    Jun 30, 2010
    Messages:
    140
    halfway through the book.
    I really like the topics in this book and how they are implemented.
    Maybe the coding step in robot repair is a bit too large for me. How would I ever have thought of a structure like that to begin with?(all the arrays and grids) :)
    Next time, maybe tone the methaphors and childrens book comments down, they really annoy me. Especially when Im frustrated about something. Its like Clipper (from Word), who is not helping when u are angry :)
    all in all a nice book, and by author thoroughly explained.
  31. jmiles

    jmiles

    New Member

    Joined:
    Oct 4, 2010
    Messages:
    14
    are the examples in the book applicable to Unity 3.0 as is without any modifications?

    thank you

    edit -----

    read through more carefully and found my answer, sorry about that
    Last edited: Nov 3, 2010
  32. cchrysostom

    cchrysostom

    New Member

    Joined:
    Oct 28, 2010
    Messages:
    1
    I purchased the book a few days ago and have made it through to chapter 7. Your simple examples and step-by-step instructions make this a great tutorial. Just what I needed to get an intro to Unity.

    I do have a question. I am using Unity 3.0. I ran into a problem adding a true type font to a material as instructed on page 185, step 7. Simply, my selection list shows only the graphics. No fonts that have been imported show up. Is there an extra step I missed?

    Thanks!
  33. mightymao

    mightymao

    New Member

    Joined:
    Oct 21, 2009
    Messages:
    108
    Well done! The book is a nice collection for my Kindle. I like the format of step by step tutorials. I just finished the Robot Repair project by converting the JavaScript to the C# without any problems. I am starting the Shoot the Moon project. By following the step by step instructions, I understand on how to use two cameras in the project.
  34. Krodil

    Krodil

    New Member

    Joined:
    Jun 30, 2010
    Messages:
    140
    I get an error for the "D2" part in the ClockScript page 190


    "
    minutes = timeRemaining/60;
    seconds = timeRemaining % 60;
    timeStr = minutes.ToString()+":";
    timeStr += seconds.ToString("D2");
    guiText.text = timeStr;//display the time to the GUI
    "

    Says the 'specified format is invalid'
  35. pixelmoon

    pixelmoon

    New Member

    Joined:
    Sep 13, 2010
    Messages:
    27
    Hi there...firts of all, congrats for your book.
    Right now I´m stuck with the "Robot repair" project. I´ve been getting the same error: "ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count" on line 66.

    This is the code:

    var cols : int = 4;
    var rows : int = 4;
    var totalCards : int = 16;
    var matchesNeededToWin : int = totalCards*0.5; // If there 16 cards, the player needs to find 8 matches to clear the board
    var matchesMade : int = 0; //At the outset, player has not made any matches
    var cardW : int = 100;
    var cardH : int = 100;
    var aCards : Array; // We store all cards in this Array
    var aGrid : Array; // Thisarray will keep track of the shuffled, dealt cards
    var aCardsFlipped : ArrayList; //This array will store two cards that the player flips over
    var playerCanClick : boolean; //prevent player clicking buttons when we don´t want to
    var playerHasWon : boolean = false;

    function Start ()
    {
    playerCanClick =true;
    aCards = new Array ();
    aGrid = new Array ();
    aCardsFlipped = new ArrayList ();
    BuildDeck();

    for (i=0; i<rows; i++)
    {
    aGrid = new Array ();//create a new array at index i

    for (j = 0; j<cols; j++)
    {
    var someNum : int = Random.Range (0,aCards.length);
    aGrid [j] = aCards [someNum];
    aCards.RemoveAt (someNum);
    }
    }
    }
    class Card extends System.Object
    {
    var isFaceUp : boolean = false;
    var isMatched : boolean = false;
    var img : String;

    function Card (img: String)
    {
    this.img=img;
    }
    }

    function OnGUI ()

    {
    GUILayout.BeginArea (Rect (0, 0, Screen.width, Screen.height));
    BuildGrid();
    GUILayout.EndArea();
    print ("building grid!");
    }

    function BuildGrid ()

    {
    GUILayout.BeginVertical ();
    GUILayout.FlexibleSpace();
    for (i=0;i<rows; i++)
    {
    GUILayout.BeginHorizontal ();
    GUILayout.FlexibleSpace();
    for (j=0;j<cols;j++)
    {
    var card : Object = aGrid [j];
    if (GUILayout.Button (Resources.Load (card.img) , GUILayout.Width (cardW)))
    {
    Debug.Log (card.img);
    }
    }
    GUILayout.FlexibleSpace();
    GUILayout.EndHorizontal ();
    }
    GUILayout.FlexibleSpace();
    GUILayout.EndVertical();
    }

    function BuildDeck ()

    {
    var totalRobots : int = 4; //we have 4 robots to work with
    var card : Object; //this stores a reference to a card
    for (i=0; totalRobots<0; i++)
    {
    var aRobotParts : Array = ["Head", "Arm", "Leg"];
    for (j=0;j<2;j++)
    {
    var someNum : int = Random.Range (0, aRobotParts.length);
    var theMissingPart : String = aRobotParts [someNum];
    aRobotParts.RemoveAt (someNum);

    card = new Card ("robot"+ (i+1) +"Missing"+ theMissingPart);
    aCards.Add (card);

    card = new Card ("robot"+ (i+1) + theMissingPart);
    aCards.Add (card);

    }
    }

    }


    Any help?
    Thanks!!
  36. yoshino

    yoshino

    New Member

    Joined:
    Aug 24, 2010
    Messages:
    11
    Seems like line.1 is wrong.
    Code (csharp):
    1. [I]var cols : int = 4;
    Delete headmost of line,.
  37. larrycharlesjr

    larrycharlesjr

    New Member

    Joined:
    Mar 10, 2010
    Messages:
    2
    Kudos on the book,

    I was looking for a good place to start learning Unity and this thread lead me to the book so I bought it!

    Thanks everyone.

    -Larry Charles.:cool:
  38. pixelmoon

    pixelmoon

    New Member

    Joined:
    Sep 13, 2010
    Messages:
    27


    Hi...thanks for the reply... the "" has nothing to do with the code. I tried to put the code in italics but it seems I forgot to put the at the end :) and therefore the you mean.

    Thanks anyway
  39. UntoldEnt

    UntoldEnt

    New Member

    Joined:
    May 5, 2009
    Messages:
    10
    Krodil - That is one bizarre error. i had the same problem with "D2" myself when i tried working with the code in Unity 3.0. Then someone i know tried it out, and there was no issue. Then i tried it out myself once more, on a different machine, with no trouble. And now you say it doesn't work.

    i've asked around, and conventional wisdom says that "D2" to round to two decimal places works just fine in both versions. i'm really curious to get to the bottom of this ... i'll let you know if i find out.

    Pixelmoon - i submitted an erratum for this section. Essentially, Unity javascript doesn't like that i tried to do math while setting the values of fields. Try one of two things:

    1. Hard-code the values, wherever they involve using the values of other variables. So instead of this:

    var matchesNeededToWin : int = totalCards * 0.5;

    do this:

    var matchesNeededToWin : int = 8;

    OR

    2. Declare the fields at the top, and define them in either the Start or Awake functions. So you'd split that line up like this:

    var matchesNeededToWin : int; // the variable is declared here (a space is reserved for it in memory)
    // other variables are declared here
    // ...
    // ...

    function Awake()
    {
    matchesNeededToWin = totalCards * 0.5; // the value is defined here (we put something in the bucket)
    }


    Hope that helps! Sorry for the slip-up.

    - Ryan
  40. pixelmoon

    pixelmoon

    New Member

    Joined:
    Sep 13, 2010
    Messages:
    27
    Hi Ryan...thanks for the reply.
    I´ve tried both but the same error persists...pretty sure I´m missing something but I don´t know what it is. Here´s the code as I´ve changed:

    var cols : int;
    var rows : int;
    var totalCards : int;
    var matchesNeededToWin : int; // the variable is declared here (a space is reserved for it in memory)
    var cardW : int;
    var cardH : int;
    var aCards : Array; // We store all cards in this Array
    var aGrid : Array; // Thisarray will keep track of the shuffled, dealt cards
    var aCardsFlipped : ArrayList; //This array will store two cards that the player flips over
    var playerCanClick : boolean; //prevent player clicking buttons when we don´t want to
    var playerHasWon : boolean = false;

    function Start ()
    {
    var cols : int = 4;
    var rows : int = 4;
    var totalCards : int = 16;
    var matchesNeededToWin : int = 8; // If there 16 cards, the player needs to find 8 matches to clear
    var matchesMade : int = 0; //At the outset, player has not made any matches
    var cardW : int = 100;
    var cardH : int = 100;
    playerCanClick =true;
    aCards = new Array ();
    aGrid = new Array ();
    aCardsFlipped = new ArrayList ();
    BuildDeck();

    for (i=0; i<rows; i++)
    {
    aGrid = new Array ();//create a new array at index i

    for (j = 0; j<cols; j++)
    {
    var someNum : int = Random.Range (0,aCards.length);
    aGrid [j] = aCards [someNum];
    aCards.RemoveAt (someNum);
    }
    }
    }
    class Card extends System.Object
    {
    var isFaceUp : boolean = false;
    var isMatched : boolean = false;
    var img : String;

    function Card (img: String)
    {
    this.img=img;
    }
    }

    function OnGUI ()

    {
    GUILayout.BeginArea (Rect (0, 0, Screen.width, Screen.height));
    BuildGrid();
    GUILayout.EndArea();
    print ("building grid!");
    }

    function BuildGrid ()

    {
    GUILayout.BeginVertical ();
    GUILayout.FlexibleSpace();
    for (i=0;i<rows; i++)
    {
    GUILayout.BeginHorizontal ();
    GUILayout.FlexibleSpace();
    for (j=0;j<cols;j++)
    {
    var card : Object = aGrid [j];
    if (GUILayout.Button (Resources.Load (card.img) , GUILayout.Width (cardW)))
    {
    Debug.Log (card.img);
    }
    }
    GUILayout.FlexibleSpace();
    GUILayout.EndHorizontal ();
    }
    GUILayout.FlexibleSpace();
    GUILayout.EndVertical();
    }

    function BuildDeck ()

    {
    var totalRobots : int = 4; //we have 4 robots to work with
    var card : Object; //this stores a reference to a card
    for (i=0; totalRobots<0; i++)
    {
    var aRobotParts : Array = ["Head", "Arm", "Leg"];
    for (j=0;j<2;j++)
    {
    var someNum : int = Random.Range (0, aRobotParts.length);
    var theMissingPart : String = aRobotParts [someNum];
    aRobotParts.RemoveAt (someNum);

    card = new Card ("robot"+ (i+1) +"Missing"+ theMissingPart);
    aCards.Add (card);

    card = new Card ("robot"+ (i+1) + theMissingPart);
    aCards.Add (card);

    }
    }

    }

    Anyway, I´ll stay tuned for the erratum.

    Thanks!!
  41. vadvaro

    vadvaro

    New Member

    Joined:
    Nov 29, 2010
    Messages:
    8
    I'm having EXACTLY the same issue with Unity 3... If i dig into the font I can see the texture file, so I know it exists. However, trying to apply it to the BlackImpact material it absolutely refuses to show up in the list of textures....HALP!
  42. UntoldEnt

    UntoldEnt

    New Member

    Joined:
    May 5, 2009
    Messages:
    10
    When you define the variables in the Awake or Start functions, don't use the var keyword.

    When you do that, you're creating a completely separate variable that is "scoped" to the function. That means that the matchesNeededToWin variable you defined at the top of the script is completely different from the matchesNeededToWin variable you defined inside the Start function.

    So use the var keyword to declare the variable at the top of the script. Then just set the value in the Start function without using the var keyword. That's how Unity knows you're talking about your instance variable.

    - Ryan
  43. pixelmoon

    pixelmoon

    New Member

    Joined:
    Sep 13, 2010
    Messages:
    27
    Oops...thanks!
    I forgot to set the var "matcheMade"...and set the values in the Start function...however, the error persists on line 75 (var card : Object = aGrid [j];)


    var cols : int;
    var rows : int;
    var totalCards : int;
    var matchesMade: int;
    var matchesNeededToWin : int; // the variable is declared here (a space is reserved for it in memory)
    var cardW : int;
    var cardH : int;
    var aCards : Array; // We store all cards in this Array
    var aGrid : Array; // Thisarray will keep track of the shuffled, dealt cards
    var aCardsFlipped : ArrayList; //This array will store two cards that the player flips over
    var playerCanClick : boolean; //prevent player clicking buttons when we don´t want to
    var playerHasWon : boolean = false;

    function Start ()
    {
    cols = 4;
    rows = 4;
    totalCards = 16;
    matchesMade = 0; //At the outset, player has not made any matches
    matchesNeededToWin = 8; // .var matchesNeededToWin : int = totalCards*0.5; If there 16 cards, the player needs to find 8 matches to clear
    cardW = 100;
    cardH = 100;
    playerCanClick =true;
    aCards = new Array ();
    aGrid = new Array ();
    aCardsFlipped = new ArrayList ();
    BuildDeck();

    for (i=0; i<rows; i++)
    {
    aGrid = new Array ();//create a new array at index i

    for (j = 0; j<cols; j++)
    {
    var someNum : int = Random.Range (0,aCards.length);
    aGrid [j] = aCards [someNum];
    aCards.RemoveAt (someNum);
    }
    }
    }

    (the rest is left out)
    Thanks
  44. yoshino

    yoshino

    New Member

    Joined:
    Aug 24, 2010
    Messages:
    11
    In the for (j = 0; j<cols; j++) nested loop In the Start() function,you should set
    Code (csharp):
    1.  
    2. aGrid[i][j] = aCards[someNum];
    3.  
    instead of
    Code (csharp):
    1.  
    2. aGrid [j] = aCards [someNum];
    3.  
    Also,check p.161 of the book.
  45. pixelmoon

    pixelmoon

    New Member

    Joined:
    Sep 13, 2010
    Messages:
    27
    Soooo weird: Dunno how I had pasted the code wrong...however it´s correct on my computer...
    Still trapped in this error...but thanks anyway
  46. vadvaro

    vadvaro

    New Member

    Joined:
    Nov 29, 2010
    Messages:
    8
    This is possibly a new bug that came about with with Unity 3.

    In chpt 7 one of the variables "isPaused" is now a reserved term for Unity itself! Took me a while to figure that out. My workaround was to change the name of the variable to "isClockPaused". Seemed to work pretty well. :)

    I still can't get the font texture to show up in the texture dialog box, however. :(
  47. pixelmoon

    pixelmoon

    New Member

    Joined:
    Sep 13, 2010
    Messages:
    27
  48. ron333

    ron333

    New Member

    Joined:
    Jan 3, 2009
    Messages:
    47
    Thanks for the above, Pixelmoon. I handled the font problem a little differently. I put a ttf font in the Project panel as you suggested. Then I made the material as suggested in steps 5, 6, and 7 on page 185. For the font texture, I used the one that came with the ttf font. I was then able to choose a Transparent/Diffuse shader as mentioned in step 8 on page 186. Now just follow steps 9, 10, 11, and 12.

    BTW, Unity 3D Game Development by Example is a terrific book.
  49. pixelmoon

    pixelmoon

    New Member

    Joined:
    Sep 13, 2010
    Messages:
    27
    I´ll take a look to that approach as well...
    You´re right...Im´kinda impressed with the clock examples...specially the last one
  50. pixelmoon

    pixelmoon

    New Member

    Joined:
    Sep 13, 2010
    Messages:
    27
    Hi again...I´ve been going through the book....and something weird is going on with the "Ticker tacker" example. After adding the MouseFollow script to the HandsAndTray Gameobject, it changes its transform on start and it goes some X and Z forward ...it seems to me it has to do with the script and the Update function because unchecking the script, HandsAndTray stays on the right place...

    Any clue on this?

    Thanks!!

    I´ve been testing first example and it goes through the same with a single gameobject (a paddle). Here´s the code (leave out some vars)

    function Update () {
    var halfW : float = Screen.width/ 2;
    transform.position.x= (Input.mousePosition.x -halfW )/halfW;

    var halfH : float = Screen.height/3;
    transform.position.z= (Input.mousePosition.y -halfH )/halfH;


    var tiltAroundZ = Input.GetAxis("Mouse X") * tiltAngle;
    var tiltAroundX = Input.GetAxis("Mouse Y") * tiltAngle;
    var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);

    // Dampen towards the target rotation
    transform.rotation = Quaternion.Slerp(transform.rotation, target,
    Time.deltaTime * smooth);


    }

    Thank you!
    Last edited: Dec 10, 2010