Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity 3D Game Development by Example

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

  1. skorpion

    skorpion

    Joined:
    Dec 31, 2010
    Posts:
    2
    Hello - I hope someone can help me.

    I went through the Robot Repair game tutorial (Chapters 5 and 6) and when I play the game I have the title screen AND the game screen at the same time. The title screen is behind the title screen. What am I doing wrong? Why is the title screen and button not appearing first?
     
  2. UntoldEnt

    UntoldEnt

    Joined:
    May 5, 2009
    Posts:
    10
    skorpion - Sounds like you may have missed the cue to separate the title screen and the game by putting the content for each in their own Scenes? You should have two Scenes: one called Title and one called Game.

    Hope that helps!

    - Ryan
     
  3. vadvaro

    vadvaro

    Joined:
    Nov 29, 2010
    Posts:
    8
    Yes that did it! Mahalo!
     
    Last edited: Jan 6, 2011
  4. vadvaro

    vadvaro

    Joined:
    Nov 29, 2010
    Posts:
    8
    and I just want to say awesome book and approach to learning the material. Really stellar way to get familiar with a lot of concepts in a very productive way.

    I'm not sure if this is a 3 thing (almost wish I had stuck with 2) but when declaring variables you need to have a space between the colon and the variable type (the book often looks like there is no space...this may just be a typography thing)

    But still, awesome, I'm going to see if my school will let me order a bunch of them as a text reference, although it would be nice to have it through a more normal vendor that works with POs the way the schools like to see the paperwork (I know they are behind the times....what else is new?)
     
  5. vadvaro

    vadvaro

    Joined:
    Nov 29, 2010
    Posts:
    8
    I don't know if this is a Unity 3D 3 change (something similiar occured in Robot Repair)

    Using the variable named "prefab" no longer seems to work, Unity now sees it as a reserved word (perhaps it no longer distinguishes it from the capitalized "Prefab". In another oddity....though the variable has no capitals in the script, when looking at the variable referenced in the inspector for the Bomb script the variable appears capitalized (this is true even if I rename the variable "monkeyButt".

    However, even after renaiming the variable I am still getting an UnassignedReferenceException

    When I open the entire project from the chpt 9 folder (and it converts it from Unity 2 to 3) then the bombs do explode and assigning the explosion gameobject prefab is recognized as attached to the "prefab" variable (despite the fact that it still shows up in color as if Unity sees it as a reserved word) HOWEVER on the project I coded from scratch nothing I assign to the variable sticks, despite showing it assigned in the preferences, which is almost looking more like a Unity glitch to me at this point.

    However the following bug is still present, even in the "finished" code downloaded from PACKT.

    The "step" animation on the character seems to only show one frame of animation and then goes back to start over playing it again. Exactly the behavior that creating the "isMoving" variable was suppossed to address.

    Both of these errors are apparent even using the downloaded finished scripts. Any and all help would be greatly appreciated!
     
    Last edited: Jan 6, 2011
  6. UntoldEnt

    UntoldEnt

    Joined:
    May 5, 2009
    Posts:
    10
    Thanks, vadvaro!

    You're right - there is no space in the book. This isn't a Unity thing - it's a code editor thing. The two code editors that ship with Unity (Unitron and Uniscite) have decided, in their infinite wisdom, that datatype keywords will only highlight if you space them out:

    var myVar:int;
    var myVar : int;

    Rest assured, the code still works without the spaces - it just doesn't look the same. Other code editors may have different highlighting rules, and this may not be the case with every editor. (I'm originally a Flash developer, and neither the Flash IDE nor the popular code editor FlashDevelop care about having that space)

    My name is Ryan, and I approve of this message.

    This is one bizarre thing Unity does. If you name a variable "monkeyButt", in the inspector panel, that will appear as "Monkey Butt". It adds spaces and capitals. i really don't know why the Unity guys decided this was a good idea. i find it confusing. Your variable is still named properly in the script, regardless of what the Inspector says.

    I've often found that if I rename the variable, the reference is lost, and I have to repeat the drag n' drop process to re-cement a connection between the variable and the Prefab. And remember, none of this will work properly if your script has errors. You need to stamp out all the errors first before you try dragging and dropping to create references. That might be your problem.

    The "step" animation on the character seems to only show one frame of animation and then goes back to start over playing it again. Exactly the behavior that creating the "isMoving" variable was suppossed to address.

    This is another bizarre thing you've hit on. I just finished teaching a Unity course at a college, using the book as the text. When we re-built the Break-Up game, I had the same problem you did - the character's Step animation was getting interrupted. One other student had the same problem. The rest didn't. It was very, very strange - we had all followed the same steps to reach that point. I want to hang back on this one and hear from more readers whether that animation worked or not, because the reports aren't consistent.

    Thanks so much for all your feedback! I'm really glad you're enjoying the book, despite these little hiccups.

    - Ryan
     
  7. Protomega

    Protomega

    Joined:
    Jan 11, 2011
    Posts:
    3
    I'm working on a game for a senior project which will involve basically killing zombies -- I'm new to Unity and have only been able to skim through C# -- Would you recommend this book?
     
  8. vadvaro

    vadvaro

    Joined:
    Nov 29, 2010
    Posts:
    8
    I throughly recommend this book! Javascript is a magnitude simpler than C-anything. I love the the fact that you're actually building games (not just exercises) and the book does a great job of building upon prior knowledge.
     
  9. vadvaro

    vadvaro

    Joined:
    Nov 29, 2010
    Posts:
    8
    Actually, my problem was I dragging the prefab into the variable area of the script itself, not the instance of the script that was a component of the game object in the scene! This is a small but critical distinction that is really not too visually easy to pick up on. I love the Unity 3d interface (it's much more organic and logically divided then the behemoth the Flash morphed into over the years, have I mentioned that I really understood ActionScript 2 and found ActionScript 3 to take twice as much code and time to squash bugs to get roughly the same functionality?)

    The assignment of prefabs into the variable visually in the Unity interface is the one piece that reminds of the niggling bit that was so prevalent in Flash where you had an association of two pieces that were visually completely separated from each other, but after finding the "instance" of the script I understand why it has to be this way. Otherwise, Unity really nailed the interface.
     
  10. vadvaro

    vadvaro

    Joined:
    Nov 29, 2010
    Posts:
    8
    One more thing, chapter 12 (the end baby) but there's no finished code for the game and I'm sure I've done something wrong when I imported the assets (the hallway just looks like a blue line in the camera)...is there a chance that will be uploaded to PACKT soon?

    O.K. I found the error. When the Hallway was imported, the FBX importer was strangely set to scale the import to .01 (what is this, a hallway for ANTS?) It was no where near the HallCam's view. Setting the scale setting to 1 and applying brought the hallway up to at least 3 times as big!

    ...and the hallCam needs to be rotated 180 (otherwise the material looks upside down, which may actually make the game a little more exciting, and you could dribble the heart down the hall...

    Mahalo!
     
    Last edited: Jan 13, 2011
  11. T_Trojan

    T_Trojan

    Joined:
    Jan 5, 2011
    Posts:
    42
    Spoilers! I didn't know there were enemies : / ...

    By the way, I was wondering, I am sorry if I missed anything, but where can I download the files for this book? I am on the robot repair I think it needs a pic of the robot, title screen etc...

    EDIT: sry downloaded from packt site.

    Did PixelMoon explain how he got pasat the ArrayOutofRange exception? I did C++ and C#, and usually that meant that index position was out of the size of the array... here however I checked and that seemed to be fine... o_O and I did avoid the math ops aka row * columns is replaced wiith 16.

    So here's the code:

    Code (csharp):
    1.  
    2.  
    3. var cols: int = 4;
    4. var rows: int = 4;
    5. var totalCards: int = 16;
    6. var matchesNeededToWin: int = 8;
    7. var matchesMade: int = 0;
    8. var cardW: int = 100;
    9. var cardH: int = 100;
    10.  
    11. var aCards: Array;
    12. var aGrid: Array;
    13.  
    14. var aCardsFlipped: ArrayList;
    15. var playerCanClick: boolean;
    16. var playerHasWon: boolean = false;
    17.  
    18. print("declaring vars");
    19. function Start()
    20. {
    21.    
    22.     playerCanClick = true;
    23.     aCqrds = new Array();  
    24.     aGrid = new Array();
    25.     aCardsFlipped = new ArrayList();
    26.     print("Before the buildeck");
    27.     BuildDeck();
    28.    
    29.     for ( i=0; i<rows;i++)
    30.     {
    31.         aGrid[i] = new Array();
    32.        
    33.         for (var j: int=0; j <cols; j++)
    34.         {
    35.             //print(i);
    36.             //print(j);
    37.             var someNum: int = Random.Range (0,aCards.length);
    38.             aGrid[i][j] = aCards[someNum]; 
    39.             aCards.RemoveAt(someNum);
    40.         }  
    41.        
    42.     }
    43. }
    44.  
    45.  
    46. class Card extends System.Object
    47. {
    48.     var isFaceUp: boolean  = false;
    49.     var isMatched: boolean = false;
    50.     var img: String;
    51.    
    52.     function Card(img: String)
    53.     {
    54.         this.img = img;
    55.        
    56.     }  
    57.    
    58. }
    59.  
    60. function OnGUI ()
    61. {
    62.     GUILayout.BeginArea (Rect(0,0,Screen.width, Screen.height));
    63.     BuildGrid();
    64.     GUILayout.EndArea();
    65.     print ("building grid!");  
    66.    
    67. }
    68.  
    69.  
    70. function BuildGrid()                               
    71. {
    72.     GUILayout.BeginVertical();
    73.     GUILayout.FlexibleSpace();
    74.     for (var i: int=0;i<rows;i++)
    75.     {
    76.         GUILayout.BeginHorizontal();
    77.         GUILayout.FlexibleSpace();
    78.         for (var j:int=0;j<cols; j++)
    79.         {
    80.             print(j);
    81.             print(i);
    82.             var card:Object = aGrid[i][j];
    83.            
    84.             if (GUILayout.Button(Resources.Load(card.img), GUILayout.Width(cardW)))
    85.             {
    86.                 Debug.Log (card.img);  
    87.             }  
    88.            
    89.         }
    90.         GUILayout.FlexibleSpace();
    91.         GUILayout.EndHorizontal(); 
    92.        
    93.     }
    94.     GUILayout.FlexibleSpace();
    95.     GUILayout.EndVertical();   
    96. }
    97.  
    98.  
    99. function BuildDeck()
    100. {
    101.     var totalRobots: int = 4;
    102.     var card: Object;
    103.    
    104.     for (i=0; i<totalRobots; i++)
    105.     {
    106.         var aRobotParts: Array = ["Head","Arm","Leg"];
    107.         for (j=0;j<2;j++)
    108.         {
    109.             print(j);
    110.             var someNum: int = Random.Range (0,aRobotParts.length);
    111.             var theMissingPart: String = aRobotParts [someNum];
    112.            
    113.             aRobotParts.RemoveAt(someNum);
    114.            
    115.             card = new Card ("robot" + (i+1) + "Missing" + theMissingPart);
    116.             aCards.Add(card);
    117.            
    118.             card = new Card ("robot" + (i+1) + theMissingPart);
    119.             aCards.Add(card);
    120.         }  
    121.     }
    122. }
    123.  
    124.  
    first error is null reference exception
    1) NullReferenceException: Object reference not set to an instance of an object
    GameScript.BuildDeck () (at Assets/Scripts/GameScript.js:114)
    GameScript.Start () (at Assets/Scripts/GameScript.js:25)

    second error keeps on repeating
    2) ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
    Parameter name: index
    0
    System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException (System.String name, System.Object actual, System.String message)
    System.Collections.ArrayList.get_Item (Int32 index)
    UnityScript.Lang.Array.get_Item (Int32 index)
    GameScript.BuildGrid () (at Assets/Scripts/GameScript.js:80)
    GameScript.OnGUI () (at Assets/Scripts/GameScript.js:61)




    I have added a few print statements for debugging, and it seems that none of my "j" or "i" values go above 0.

    Thanks :)

    ====================
    EDIT 2

    Alright, I think I got it, if anyone needs a working code for page 162, here:

    Code (csharp):
    1.  
    2.  
    3.  
    4. var cols: int = 4;
    5. var rows: int = 4;
    6. var totalCards: int = 16;
    7. var matchesNeededToWin: int = totalCards * 0.5;
    8. var matchesMade: int = 0;
    9. var cardW: int = 100;
    10. var cardH: int = 100;
    11. var aCards: Array;
    12. var aGrid: Array;
    13. var aCardsFlipped: ArrayList;
    14. var playerCanClick: boolean;
    15. var playerHasWon: boolean = false;
    16.  
    17. function Start()
    18. {
    19.    
    20.     playerCanClick = true;
    21.     aCards = new Array();  
    22.     aGrid = new Array();
    23.     aCardsFlipped = new ArrayList();
    24.     BuildDeck();
    25.    
    26.     for ( i=0; i<rows;i++)
    27.     {
    28.         aGrid[i] = new Array();
    29.        
    30.         for (var j: int=0; j <cols; j++)
    31.         {
    32.             var someNum: int = Random.Range (0,aCards.length);
    33.             aGrid[i][j] = aCards[someNum]; 
    34.             aCards.RemoveAt(someNum);
    35.         }  
    36.        
    37.     }
    38. }
    39.  
    40.  
    41. class Card extends System.Object
    42. {
    43.     var isFaceUp: boolean  = false;
    44.     var isMatched: boolean = false;
    45.     var img: String;
    46.    
    47.     function Card(img: String)
    48.     {
    49.         this.img = img;
    50.        
    51.     }  
    52.    
    53. }
    54.  
    55. function OnGUI ()
    56. {
    57.     GUILayout.BeginArea (Rect(0,0,Screen.width, Screen.height));
    58.     BuildGrid();
    59.     GUILayout.EndArea();   
    60. }
    61.  
    62.  
    63. function BuildGrid()                               
    64. {
    65.     GUILayout.BeginVertical();
    66.     GUILayout.FlexibleSpace();
    67.     for (var i: int=0;i<rows;i++)
    68.     {
    69.         GUILayout.BeginHorizontal();
    70.         GUILayout.FlexibleSpace();
    71.         for (var j:int=0;j<cols; j++)
    72.         {
    73.             var card:Object = aGrid[i][j];
    74.            
    75.             if (GUILayout.Button(Resources.Load(card.img), GUILayout.Width(cardW)))
    76.             {
    77.                 Debug.Log (card.img);  
    78.             }  
    79.            
    80.         }
    81.         GUILayout.FlexibleSpace();
    82.         GUILayout.EndHorizontal(); 
    83.        
    84.     }
    85.     GUILayout.FlexibleSpace();
    86.     GUILayout.EndVertical();   
    87. }
    88.  
    89.  
    90. function BuildDeck()
    91. {
    92.     var totalRobots: int = 4;
    93.     var card: Object;
    94.    
    95.     for (i=0; i<totalRobots; i++)
    96.     {
    97.         var aRobotParts: Array = ["Head","Arm","Leg"];
    98.         for (j=0;j<2;j++)
    99.         {
    100.             var someNum: int = Random.Range (0,aRobotParts.length);
    101.             var theMissingPart: String = aRobotParts [someNum];
    102.            
    103.             aRobotParts.RemoveAt(someNum);
    104.            
    105.             card = new Card ("robot" + (i+1) + "Missing" + theMissingPart);
    106.             aCards.Add(card);
    107.            
    108.             card = new Card ("robot" + (i+1) + theMissingPart);
    109.             aCards.Add(card);
    110.         }  
    111.     }
    112. }
    113.      
    114.  
     
    Last edited: Jan 14, 2011
  12. blub

    blub

    Joined:
    Jan 13, 2011
    Posts:
    2
    Hi everyone, im new to this whole scripting thing so sorry if it's an obvious mistake i made... i followed chapters 5 and 6 to make the robot repair game, somehow when i press play i'm stuck with a compiler error:

    "expecting ":" found ";"

    it says it's an error made in line 80 of my code...

    here's the whole function...

    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];
    var img:String;

    if(card.isMatched)
    {
    img = "blank";
    }
    else
    {
    if(card.isFaceUp)
    {
    img = card.img;
    }
    else
    {
    img = "wrench";
    }
    }

    GUI.enabled = !card.isMatched;
    if(GUILayout.Button(Resources.Load(img),GUILayout.Width(cardW)))
    {
    if(playerCanClick) FlipCardFaceUp(card);
    {
    Debug.Log(card.img);
    }
    GUI.enabled = true;
    }
    }
    GUILayout.FlexibleSpace();
    GUILayout.EndHorizontal();
    }
    GUILayout.FlexibleSpace();
    GUILayout.EndVertical();
    }


    the bold place is where it says it found an error

    can anyone help me solve this problem please?

    any help appreciated...
     
  13. T_Trojan

    T_Trojan

    Joined:
    Jan 5, 2011
    Posts:
    42


    Hi, that if statement is incorrect, FlipCardFaceUp(card); should go inside the if statement aka between the braces
    so that the end result looks like this

    Code (csharp):
    1.  
    2. if (GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW)))
    3. {
    4.     if (playerCanClick)
    5.     {
    6.         FlipCardFaceUp(card);
    7.     }
    8.     Debug.Log (card.img);  
    9. }  
    10.  
    ===============================================

    Oh actually on topic

    UnToldEnt, I am just about done the robot program and here's what I think so far:

    Compared to Unity Essentials book, this one is alot more code heavy, for example it introduces loops and arrays whereas in essentials basically as complex as it goes is the if statements, that makes me wonder, should there be an index at the end of the book with completed code?

    As in, not fragmented, because it takes a long time to debug and figure out small things.

    Also another thing I have noticed, on page 176: when you add the line to the existing code in order to modify the function, the existing code is slightly different so when double checking it makes one doubtful

    for example: the for loop it used the format of

    for( i =0; i<something; i++)

    and later on it suddenly changed to

    for (var i: int =0; i<something; i++)

    While speaking of consistency here, in the beginning of the book you mentioned that operations such as *0.5 are faster than /2.

    On p. 177 you used a division method, although I am not sure if there was a specific reason for that (I tried multiplication it worked fine)

    Other than that, everything so far is going smoothly, it's quite comprehensive.
    Sorry if any of the above were already mentioned.

    hope it helps!
     
    Last edited: Jan 14, 2011
  14. blub

    blub

    Joined:
    Jan 13, 2011
    Posts:
    2
    thank you very very very very very freakin' much! :D :D :D

    thank you :D

    i finally have my game working now XD
     
  15. dadako

    dadako

    Joined:
    Jul 17, 2010
    Posts:
    66
    First off, great book so far.

    Second off, there appears to be a few errors as people have covered however the real stickler is on page 174.

    Basically the code for BuildGrid() isn't functioning. It throws out an error for:

    Code (csharp):
    1.  
    2. function BuildGrid()
    3. {
    4.     GUILayout.BeginVertical();
    5.     GUILayout.FlexibleSpace();
    6.     for(i=0; i<rows; i++)
    7.     {
    8.         GUILayout.BeginHorizontal();
    9.         GUILayout.FlexibleSpace();
    10.         for(j=0; j<cols; j++)
    11.         {
    12.             var card:Object = aGrid[i][j];
    13.             var img:String;
    14.             if(card.isMatched)
    15.             {
    16.                 img = "blank";
    17.             }
    18.             else
    19.             {
    20.                 if(card.isFaceUp)
    21.                 {
    22.                     img = card.img;
    23.                 }
    24.                 else
    25.                 {
    26.                     img = "wrench";
    27.                 }
    28.             }
    29.        GUI.enabled = !card.isMatched;
    30.        if(GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW)))
    31.        {
    32.             if(playerCanClick) FlipCardFaceUp(card);
    33.             {
    34.                 [B]Debug.Log(card.img);[/B]
    35.             }
    36.             GUI.enabled = true;
    37.         }
    38.         GUILayout.FlexibleSpace();
    39.         GUILayout.EndHorizontal();
    40.     }
    41.     GUILayout.FlexibleSpace();
    42.     GUILayout.EndVertical();
    43. }
    44.  
    The Error says that an : was expected where a ; was present (highlighted in bold)

    Earlier in the book, the code for this area different, placing FlipCardFaceUp(card); in it's own curly brackets.

    Basically this error has stopped my progress in it's tracks as I'm not seasoned enough to fix this. A web page with known errors (like many other self help books offer) would be nice.

    [edit] if editing code to the above fix, it breaks code later on on the file, when encountering the Card Function in BuildDeck

    [/edit]
     
    Last edited: Jan 17, 2011
  16. T_Trojan

    T_Trojan

    Joined:
    Jan 5, 2011
    Posts:
    42
    Yeah I looked over your BuildGrid(), if you've already fixed it according to my previous post, then you will need to post your entire code.

    It's not an error in this function anymore.
     
  17. dadako

    dadako

    Joined:
    Jul 17, 2010
    Posts:
    66
    I was able to fix this by going back and starting earlier in the tutorial, then applying your fix T_Trojan.

    I think the most confusing part of this book or this chapter is the tendency to do this:

    Code (csharp):
    1. // (some stuff was omitted here for clarity)
    no :( it just got 10 times more confusing!! I have no idea where to insert this code when just given the function then the first line in bold that should be edited.

    Another problem, the book only comes with resources and no code until chapter 8 (not actually checked that out yet, may not even contain the code) - no "official" code to compare my workings to.

    I have done the cards bit now but completed cards are not going blank. No idea why. Here's my BuildGrid for reference:

    Code (csharp):
    1.  
    2.  
    3. function BuildGrid()
    4. {
    5.     GUILayout.BeginVertical();
    6.     GUILayout.FlexibleSpace();
    7.     for(i=0; i<rows; i++)
    8.     {
    9.         GUILayout.BeginHorizontal();
    10.         GUILayout.FlexibleSpace();
    11.         for(j=0; j<cols; j++)
    12.         {
    13.             var card:Object = aGrid[i][j];
    14.             var img:String;
    15.             //insert here one guesses... not very clear
    16.             if(card.isMatched)
    17.             {
    18.                 img = "blank";
    19.             }
    20.             else if(card.isFaceUp)
    21.                 {
    22.                     img = card.img;
    23.                 }
    24.             else
    25.                 {
    26.                     img = "wrench";
    27.                 }
    28.            
    29.             GUI.enabled = !card.isMatched;
    30.             if(GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW)))
    31.             {
    32.                 if(playerCanClick) //heres where the book has an error
    33.                 {
    34.                     FlipCardFaceUp(card);
    35.                 }
    36.                 Debug.Log(card.img);
    37.                 GUI.enabled = true;
    38.             }
    39.         }
    40.         GUILayout.FlexibleSpace();
    41.         GUILayout.EndHorizontal();
    42.     }
    43.     GUILayout.FlexibleSpace();
    44.     GUILayout.EndVertical();
    45. }
    46.  
    (I messed about with the else if statement to make it more readable to my js brain, doesn't actually make any difference AFAICS)
     
    Last edited: Jan 17, 2011
  18. T_Trojan

    T_Trojan

    Joined:
    Jan 5, 2011
    Posts:
    42
    hmm, try this. Although if that doesn't work I would compare the entire code.

    Code (csharp):
    1.  
    2. GUI.enabled = !card.isMatched;
    3. if(GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW)))
    4. {
    5.     if(playerCanClick) //heres where the book has an error
    6.     {
    7.         FlipCardFaceUp(card);
    8.     }
    9.     Debug.Log(card.img);
    10.     GUI.enabled = true;
    11. }
    12.  

    Code (csharp):
    1.  
    2. GUI.enabled = !card.isMatched;
    3. if (GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW)))
    4. {
    5.     if (playerCanClick)
    6.     {
    7.         FlipCardFaceUp(card);
    8.     }
    9. [B]Debug.Log (card.img);   
    10. }  
    11. GUI.enabled = true; [/B]
    12.  

    and might as well the entire code (before the clock thing, and too many lines to format it properly)

    Code (csharp):
    1.  
    2. var cols: int = 4;
    3. var rows: int = 4;
    4. var totalCards: int = 16;
    5. var matchesNeededToWin: int = totalCards * 0.5;
    6. var matchesMade: int = 0;
    7. var cardW: int = 100;
    8. var cardH: int = 100;
    9. var aCards: Array;
    10. var aGrid: Array;
    11. var aCardsFlipped: ArrayList;
    12. var playerCanClick: boolean;
    13. var playerHasWon: boolean = false;
    14.  
    15.  
    16. function Start()
    17. {
    18.    
    19.     playerCanClick = true;
    20.     aCards = new Array();  
    21.     aGrid = new Array();
    22.     aCardsFlipped = new ArrayList();
    23.     BuildDeck();
    24.    
    25.     for ( i=0; i<rows;i++)
    26.     {
    27.         aGrid[i] = new Array();
    28.        
    29.         for (var j: int=0; j <cols; j++)
    30.         {
    31.             var someNum: int = Random.Range (0,aCards.length);
    32.             aGrid[i][j] = aCards[someNum]; 
    33.             aCards.RemoveAt(someNum);
    34.         }  
    35.        
    36.     }
    37. }
    38.  
    39.  
    40. class Card extends System.Object
    41. {
    42.     var isFaceUp: boolean  = false;
    43.     var isMatched: boolean = false;
    44.     var img: String;
    45.     var id: int;
    46.    
    47.     function Card(img: String, id:int)
    48.     {
    49.         this.img = img;
    50.         this.id = id;
    51.        
    52.     }  
    53.    
    54. }
    55.  
    56. function OnGUI ()
    57. {
    58.     GUILayout.BeginArea (Rect(0,0,Screen.width, Screen.height));
    59.     BuildGrid();
    60.     if (playerHasWon) BuildWinPrompt();
    61.     GUILayout.EndArea();   
    62. }
    63.  
    64.  
    65. function BuildGrid()                               
    66. {
    67.     GUILayout.BeginVertical();
    68.     GUILayout.FlexibleSpace();
    69.     for (var i: int=0;i<rows;i++)
    70.     {
    71.         GUILayout.BeginHorizontal();
    72.         GUILayout.FlexibleSpace();
    73.         for (var j:int=0;j<cols; j++)
    74.         {
    75.             var card:Object = aGrid[i][j];
    76.             var img: String;
    77.            
    78.             if(card.isMatched)
    79.             {
    80.                 img = "blank"; 
    81.             }
    82.             else
    83.             {
    84.                 if (card.isFaceUp)
    85.                 {
    86.                     img = card.img;
    87.                 }
    88.                 else
    89.                 {
    90.                     img = "wrench";
    91.                 }
    92.             }
    93.            
    94.             GUI.enabled = !card.isMatched;
    95.             if (GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW)))
    96.             {
    97.                 if (playerCanClick)
    98.                 {
    99.                     FlipCardFaceUp(card);
    100.                 }
    101.             Debug.Log (card.img);  
    102.             }  
    103.             GUI.enabled = true;
    104.         }
    105.         GUILayout.FlexibleSpace();
    106.         GUILayout.EndHorizontal(); 
    107.        
    108.     }
    109.     GUILayout.FlexibleSpace();
    110.     GUILayout.EndVertical();   
    111.    
    112.  
    113. }
    114.  
    115.  
    116. function BuildDeck()
    117. {
    118.     var totalRobots: int = 4;
    119.     var card: Object;
    120.     var id: int = 0;
    121.    
    122.     for (i=0; i<totalRobots; i++)
    123.     {
    124.         var aRobotParts: Array = ["Head","Arm","Leg"];
    125.         for (j=0;j<2;j++)
    126.         {
    127.             var someNum: int = Random.Range (0,aRobotParts.length);
    128.             var theMissingPart: String = aRobotParts [someNum];
    129.            
    130.             aRobotParts.RemoveAt(someNum);
    131.            
    132.             card = new Card ("robot" + (i+1) + "Missing" + theMissingPart, id);
    133.             aCards.Add(card);
    134.            
    135.             card = new Card ("robot" + (i+1) + theMissingPart, id);
    136.             aCards.Add(card);
    137.             id++;
    138.         }  
    139.     }
    140. }
    141.      
    142.  
    143. function FlipCardFaceUp(card: Card)
    144. {
    145.     card.isFaceUp = true;
    146.    
    147.     if (aCardsFlipped.IndexOf(card)<0)
    148.     {
    149.         aCardsFlipped.Add(card);
    150.     }
    151.    
    152.     if (aCardsFlipped.Count == 2 )
    153.     {
    154.         playerCanClick = false;
    155.         yield WaitForSeconds (1);
    156.        
    157.         if ( aCardsFlipped[0].id == aCardsFlipped[1].id)
    158.         {
    159.             aCardsFlipped[0].isMatched = true;
    160.             aCardsFlipped[1].isMatched = true;
    161.             matchesMade ++;
    162.            
    163.             if (matchesMade >= matchesNeededToWin)
    164.             {
    165.                 playerHasWon = true;   
    166.             }
    167.         }
    168.         else
    169.         {
    170.             aCardsFlipped[0].isFaceUp = false;
    171.             aCardsFlipped[1].isFaceUp = false;
    172.         }
    173.         aCardsFlipped = new ArrayList();
    174.        
    175.         playerCanClick = true;
    176.     }
    177. }      
    178.    
    179. function BuildWinPrompt()
    180. {
    181.     var winPromptW: int = 100;
    182.     var winPromptH = 90;
    183.    
    184.     var halfScreenW: float = Screen.width*0.5;
    185.     var halfScreenH: float = Screen.height*0.5;
    186.    
    187.     var halfPromptW: int = winPromptW*0.5;
    188.     var halfPromptH: int = winPromptH*0.5; 
    189.    
    190.     GUI.BeginGroup(Rect(halfScreenW - halfPromptW, halfScreenH - halfPromptH, winPromptW, winPromptH));
    191.     GUI.Box(Rect (0,0, winPromptW, winPromptH), "A winner is You!!");
    192.    
    193.     if (GUI.Button(Rect(10,40,80,20), "Play Again"))
    194.     {
    195.         Application.LoadLevel("Title");
    196.            
    197.     }
    198.     GUI.EndGroup();
    199.    
    200.    
    201. }
    202.  
    203.  
    204.  
    I also am not quite sure how I got around theses issues since the book clearly points to one thing, maybe I read the posts on previous pages, but I forget tbh.
     
    Last edited: Jan 17, 2011
  19. dadako

    dadako

    Joined:
    Jul 17, 2010
    Posts:
    66
    Shiny working code for chapter 6 - same as T_Trojans despite a few formatting variations - thanks ever so much!

    Code (csharp):
    1.  
    2. var cols:int = 4;
    3. var rows:int = 4;
    4. var totalCards:int = cols*rows;
    5. var matchesNeededToWin:int = totalCards * 0.5;
    6. var matchesMade:int = 0;
    7. var cardW:int = 100; //pixel width of card
    8. var cardH:int = 100; //pixel height of card
    9. var aCards:Array; //stores created cards
    10. var aGrid:Array; //keeping track of shuffled and dealt cards
    11. var aCardsFlipped:ArrayList; //this array is for Storing the two cards flipped
    12. var playerCanClick:boolean;
    13. var playerHasWon:boolean = false;
    14.  
    15. function Start() //setting up the game
    16. {
    17.     playerCanClick = true;
    18.     aCards = new Array();
    19.     aGrid = new Array();
    20.     aCardsFlipped = new ArrayList();
    21.     BuildDeck();
    22.    
    23.     for(var i=0; i<rows; i++)
    24.     {
    25.         aGrid[i] = new Array(); //new Array at index? i
    26.        
    27.         for(var j=0; j<cols; j++)
    28.         {
    29.             var someNum:int = Random.Range(0,aCards.length);
    30.             aGrid[i][j] = aCards[someNum];
    31.             aCards.RemoveAt(someNum);
    32.         }
    33.     }
    34. }
    35.  
    36. class Card extends System.Object
    37. {
    38.     var isFaceUp:boolean = false;
    39.     var isMatched:boolean = false;
    40.     var img:String; //stores the name of the Card
    41.     var id:int;
    42.    
    43.     function Card(img:String, id:int)
    44.     {
    45.         this.img = img;
    46.         this.id = id;
    47.     }
    48. }
    49.  
    50. function OnGUI () {
    51.     GUILayout.BeginArea (Rect (0,0,Screen.width, Screen.height));
    52.     GUILayout.BeginHorizontal();
    53.     BuildGrid();
    54.     if(playerHasWon) BuildWinPrompt();
    55.     GUILayout.EndHorizontal();
    56.     GUILayout.EndArea();
    57. }
    58.  
    59. function BuildGrid()
    60. {
    61.     GUILayout.BeginVertical();
    62.     GUILayout.FlexibleSpace();
    63.     for(i=0; i<rows; i++)
    64.     {
    65.         GUILayout.BeginHorizontal();
    66.         GUILayout.FlexibleSpace();
    67.         for(j=0; j<cols; j++)
    68.         {
    69.             var card:Object = aGrid[i][j];
    70.             var img:String;
    71.            
    72.             if(card.isMatched)
    73.             {
    74.                 img = "blank"; //book error add semicolon
    75.             }
    76.             else
    77.             {
    78.                 if(card.isFaceUp)
    79.                 {
    80.                     img = card.img;
    81.                 }
    82.                 else
    83.                 {
    84.                     img = "wrench";
    85.                 }
    86.             }
    87.            
    88.             GUI.enabled = !card.isMatched;
    89.             if(GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW)))
    90.             {
    91.                 if(playerCanClick) //heres where the book has an error
    92.                 {
    93.                     FlipCardFaceUp(card);
    94.                 }
    95.             Debug.Log(card.img);
    96.             }
    97.             GUI.enabled = true;
    98.         }
    99.         GUILayout.FlexibleSpace();
    100.         GUILayout.EndHorizontal();
    101.     }
    102.     GUILayout.FlexibleSpace();
    103.     GUILayout.EndVertical();
    104. }
    105.  
    106. function BuildDeck()
    107. {
    108.     var totalRobots:int = 4; // defines how many robots there are
    109.     var card:Object; //stores reference to a card
    110.     var id:int = 0;
    111.     for(i=0; i<totalRobots; i++)
    112.     {
    113.         var aRobotParts:Array = ["Head", "Arm", "Leg"];
    114.         for(j=0; j<2; j++)
    115.         {
    116.             var someNum:int = Random.Range(0, aRobotParts.length);
    117.             var theMissingPart:String = aRobotParts[someNum];
    118.             aRobotParts.RemoveAt(someNum);
    119.             card = new Card("robot" + (i+1) + "Missing" + theMissingPart, id);
    120.             aCards.Add(card);
    121.             card = new Card("robot" + (i+1) + theMissingPart, id);
    122.             aCards.Add(card);
    123.             id++;
    124.         }
    125.     }
    126. }
    127.  
    128. function FlipCardFaceUp(card:Card)
    129. {
    130.     card.isFaceUp = true;
    131.     if(aCardsFlipped.IndexOf(card) < 0)
    132.     {
    133.         aCardsFlipped.Add(card);
    134.     }
    135.     if(aCardsFlipped.Count == 2)
    136.     {
    137.         playerCanClick = false;
    138.        
    139.         yield WaitForSeconds(1);
    140.        
    141.         if(aCardsFlipped[0].id == aCardsFlipped[1].id)
    142.         {
    143.             //match!!
    144.             aCardsFlipped[0].isMatched = true; //check
    145.             aCardsFlipped[1].isMatched = true;
    146.            
    147.             matchesMade ++;
    148.            
    149.             if(matchesMade >= matchesNeededToWin)
    150.             {
    151.                 playerHasWon = true;
    152.             }
    153.         }
    154.         else
    155.         {
    156.             aCardsFlipped[0].isFaceUp = false; //check
    157.             aCardsFlipped[1].isFaceUp = false;
    158.         }
    159.         aCardsFlipped = new ArrayList(); //open the array again
    160.        
    161.         playerCanClick = true;
    162.     }
    163. }
    164.  
    165. function BuildWinPrompt()
    166. {
    167.     var winPromptW:int = 100;
    168.     var winPromptH:int = 90;
    169.    
    170.     var halfScreenW:float = Screen.width * 0.5;
    171.     var halfScreenH:float = Screen.height * 0.5;
    172.    
    173.     var halfPromptW:int = winPromptW * 0.5;
    174.     var halfPromptH:int = winPromptH * 0.5;
    175.    
    176.     GUI.BeginGroup(Rect(halfScreenW-halfPromptW, halfScreenH-halfPromptH, winPromptW, winPromptH));
    177.     GUI.Box (Rect (0,0,winPromptW,winPromptH), "you win");
    178.     if(GUI.Button(Rect(10,40,80,20), "play again"))
    179.     {
    180.         Application.LoadLevel("title");
    181.     }
    182.     GUI.EndGroup();
    183. }
    184.  
    185.  
    186.  
    187.  
    188.  
     
    Last edited: Jan 17, 2011
  20. dadako

    dadako

    Joined:
    Jul 17, 2010
    Posts:
    66
    Thanks for posting your code T_Trojan, I'm comparing now! ;) happy days
     
  21. dadako

    dadako

    Joined:
    Jul 17, 2010
    Posts:
    66
    ah... My mistake was one of true and false in function FlipCardFaceUp(card: Card)

    I had
    Code (csharp):
    1.  aCardsFlipped[0].isMatched =
    set to false :p
     
  22. T_Trojan

    T_Trojan

    Joined:
    Jan 5, 2011
    Posts:
    42
  23. eedok

    eedok

    Joined:
    Sep 21, 2009
    Posts:
    194
    Is there a place to download the completed Ticker project? I think I made a mistake somewhere as the hallways are overlapping the gameplay area and the limited numbers that are listed in the book match up.
     
  24. dadako

    dadako

    Joined:
    Jul 17, 2010
    Posts:
    66
    OK just keeping a log in this thread of errors you might come across in the book that will break your code for future googlers / bingers.

    Page 196 Part 4:

    Code (csharp):
    1. GUI.BeginGroup (new Rect Screen.width - clockBG.width - gap, gap, clockBG.width, clockBG.height));
    should be:

    Code (csharp):
    1. GUI.BeginGroup (new Rect (Screen.width - clockBG.width - gap, gap, clockBG.width, clockBG.height));
    This is actually corrected on the following page, it's an easy one to spot because of the two closing brackets.

    (it's a good book, really! Just a few tiny code errors but in all honesty I think they help, learning to spot errors is now helping me to learn how to code.)
     
    Last edited: Jan 19, 2011
  25. Zigmiceter

    Zigmiceter

    Joined:
    Feb 12, 2011
    Posts:
    1
    Hey, I don't know where to get the art assets package, and I need it to continue in the book. can you give me a download link?
     
  26. DarkKnight

    DarkKnight

    Joined:
    Apr 2, 2011
    Posts:
    22
    Not sure what i've done wrong but in chapter 5 of robot repair all I get is a white screen no grid and no cards.
    Also I don't get any script errors , been trying to find out if I did link something but can't seem to find the problem.
    The title scene works fine it's just the game scene.
    can someone please point me in the right direction ??

    var cols : int = 4; // the number of columns in the card grid
    var rows : int = 4; // the number of rows in the card grid
    var totalCards : int = cols*rows; // i think the number is 16 , but i was never good with numbers.
    var matchesNeededToWin : int = totalCards * 0.5; // if there is 16 cards, the player needs to find 8 matches to claer the board
    var matchesMade : int = 0;// at the outset, the player has not made any matches.
    var cardW : int = 100; // each cards width and height is 100 pixels
    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 aCardFlipped : ArrayList; // this array will store the two cards that the player flips over
    var playerCanClick : boolean; // we'll use this flag to prevent the player from clicking buttons when we don't want him to.
    var playerHasWon : boolean = false; // store whether or not the player has won. this should probably start out false:)
    function Start()
    {
    playerCanClick = true; // We should let the player play.
    // Initialize the array as empty lists:
    aCard = new Array();
    aGrid = new Array();
    aCardsFlipped = new ArrayList();
    for (i=0; i<rows; i++)
    {
    aGrid = new Array(); // Create a new , empty 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));
    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();
    }
     
    Last edited: Apr 2, 2011
  27. Mahshid

    Mahshid

    Joined:
    Apr 5, 2011
    Posts:
    3
    Hi!

    I have a question.can we fill grid without using any package and use different pic by leave this pic in unity resource file?
    i do that, for title screen it work but it didn't work for fill grid and i don't know which codes line are for package , that i change them:)!
     
  28. Mahshid

    Mahshid

    Joined:
    Apr 5, 2011
    Posts:
    3
    no body answer me :(
     
  29. chclau

    chclau

    Joined:
    Apr 4, 2011
    Posts:
    20
    For Darknight: I see you left the Update function there. I think you have to erase it. Not sure if it is all the problem, though


    To the book author: I am reading it right now, I like it, the way you teach and your sense of humor. I have a small critic, though, that for being a Unity book, 3D coverage is rather thin.

    Thanks!
     
  30. DarkKnight

    DarkKnight

    Joined:
    Apr 2, 2011
    Posts:
    22
    Ok I figured out chapter 5 6
    I've started chapter 7 and right out of the gate i'm getting errors for line 25 and 27
    Is there someting i'm doing wrong ( should I use a different compiler then the default )


    Assets/Scripts/clockScript.js(25,10): BCE0044: expecting (, found 'PauseClock'.

    Assets/Scripts/clockScript.js(25,23): UCE0001: ';' expected. Insert a semicolon at the end.

    Assets/Scripts/clockScript.js(27,18): BCE0044: expecting :, found '='.




    var isPaused : boolean = false;
    var startTime : float; //(in seconds)
    var timeRemaining : float; // ( in seconds)
    function Start() {
    startTime = 5.0;
    }
    function Update () {
    if (! isPaused)
    {
    // make sure the timer is not paused
    DoCountdown();
    }
    }
    function DoCountdown()
    {
    timeRemaining = startTime - Time.time;
    if (timeRemaining < 0)
    {
    timeRemaining = 0;
    isPaused = true;
    TimeIsUp();
    Debug.Log("time remaining = " + timeRemaining);
    }

    function PauseClock () error line 25
    {
    isPaused = true; error line 27
    }

    function UnpausedClock ()
    {
    isPaused = false;
    }

    function ShowTime()
    {
    }

    function TimeIsUp()
    {
    Debug.Log ("Time is up!");
    }
     
  31. chclau

    chclau

    Joined:
    Apr 4, 2011
    Posts:
    20
    Darknight, you have a missing } bracket at the end of the DoCountDown function.
     
  32. DarkKnight

    DarkKnight

    Joined:
    Apr 2, 2011
    Posts:
    22
    Thanks for your help chclau
    I'm new to scripting , from what you showed me I assume when I finish a function it should end with 2 } } brackets like this

    function DoCountdown()
    {
    timeRemaining = startTime - Time.time;
    if (timeRemaining < 0)
    {
    timeRemaining = 0;
    isPaused = true;
    TimeIsUp();
    Debug.Log("time remaining = " + timeRemaining);
    }
    }
     
  33. chclau

    chclau

    Joined:
    Apr 4, 2011
    Posts:
    20
    Not exactly
    The first bracket ends the if clause, the second one ends the function block.

    And I suggest that you use indentation to avoid those mistakes.
    Also, use some good formated editor for your Javascripts.
    I use Jedit, a free one.
     
  34. T_Trojan

    T_Trojan

    Joined:
    Jan 5, 2011
    Posts:
    42
    Yes you can fill the grid without the package, if you want to see if you are building the grid properly anything will work fine. If you are having trouble with fill grid, try using smallish square tiles. If you follow the book and previous forums posts, it should work fine.

    Indentation is removed when the code is pasted in forums without
    Code (csharp):
    1.  tags.
    2. Unitron and Uniscite that come with Unity work fine as well.
     
    Last edited: Apr 11, 2011
  35. jbernardo

    jbernardo

    Joined:
    Apr 11, 2011
    Posts:
    1
    Great Book. kudos to Ryan.. When trying to increase the grid size from (cols = 4 and rows = 4) to say (cols = 5 , rows = 5) I get an ArgumentOutOfRangeException. However, decreasing the grid (cols or rows) to <=4 is fine and will build the new grid accordingly. Am I missing something obvious ?
     
  36. DarkKnight

    DarkKnight

    Joined:
    Apr 2, 2011
    Posts:
    22
    I understand the basic concept of scritping and know where to look things up if I'm not sure how to do something.
    But I can't seem to get a handle on where , when and why for the { brackets.
    all examples and anything I read don't state why or where, they all just seem to assume there is an understanding.

    for example this function ends with 3

    function Start() //setting up the game
    {
    playerCanClick = true;
    aCards = new Array();
    aGrid = new Array();
    aCardsFlipped = new ArrayList();
    BuildDeck();

    for(var i=0; i<rows; i++)
    {
    aGrid = new Array(); //new Array at index? i

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

    and the next example I really don't understand

    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];
    var img:String;

    if(card.isMatched)
    {
    img = "blank"; //book error add semicolon
    }
    else
    {
    if(card.isFaceUp)
    {
    img = card.img;
    }
    else
    {
    img = "wrench";
    }
    }

    So right now the biggest problem I'm facing , is that some of my scripts get errors for this fact
    if someone can please point me in the right direction or some where I can find this imformation.

    Thanks
     
  37. Mahshid

    Mahshid

    Joined:
    Apr 5, 2011
    Posts:
    3
    thanks.i try it again .
     
  38. chclau

    chclau

    Joined:
    Apr 4, 2011
    Posts:
    20
    Darknight,

    Brackets {} delimit blocks of code

    A function is a block of code, so after a function you will have an opening and a closing bracket
    A for sentence also has a block of code
    An if clause also preceeds a block of code, and an else sentence also opens its own block of code.

    If you don't understand this try to do very simple code scripts until you fully understand code blocks.
    I wish you success!
     
  39. Stone Fury

    Stone Fury

    Joined:
    Apr 16, 2011
    Posts:
    2
    Hello,
    My first post. I hope I am posting this in the correct thread. In Chapter 5 on page 129 about importing assets for the Robot Repair game. It says to click on Assets - Import Package (I'm assuming Assets - Import Package - Custom Package...) and when I get to the asset folders I downloaded it is not letting me select any of them to import. I go into the folders and I get "No items match your search". Can someone please let me know what I am doing wrong? Many thanks in advance!
     
  40. yoshino

    yoshino

    Joined:
    Aug 24, 2010
    Posts:
    11
    If you correctly downloaded from the site,in the folder ch05.unitypackage will be there.
    I could import it.Of course via Asset/Import Package/Custom Package.And make sure that not select to Import New Asset.This case can't select unitypackage files.
     
  41. Stone Fury

    Stone Fury

    Joined:
    Apr 16, 2011
    Posts:
    2
    Ahh, an error on my part. Unfortunately my first post was a total brain fart on my end.
     
  42. andie12serador

    andie12serador

    Joined:
    Apr 17, 2011
    Posts:
    3
    any video tut ? im tired of reading books
     
  43. jstriedinger

    jstriedinger

    Joined:
    Apr 19, 2011
    Posts:
    58
    Hi!

    I already read Unity Essentials and now Im with this book :D. I'm on chapter 5, but I have no idea where that asset package is, I mean... it never says where to download it from...

    Help please! thanks :D
     
  44. jstriedinger

    jstriedinger

    Joined:
    Apr 19, 2011
    Posts:
    58
    Never mind about the assets, I already founf them (You dont make very clear how to download it)

    I'm in ch9 doing the 'Break-Up' game and I'm in the part when I call the animation on the character model. I'm doing EXACTLY what you are telling us in the book, but every time I call any animation with I get the following error message: "The animation stat idle (or step or catch) could not be played because it couldn't be found!"

    Please I could really use some help on this. I don't know what's wrong... =/
     
  45. DarkKnight

    DarkKnight

    Joined:
    Apr 2, 2011
    Posts:
    22
    I seem to have a problem in chapter 8 , I don't have any errors in my script . But it doesn't seem to be doing anything
    the GUI text shows 0 and thats about it .
    the hitcount and bestscore doesn't seem to be doing anything.
    I have both the hand and tray mesh tagged to tray
    also have the heart bounce script attacted to the heart folder along with the bounce count GUI attached to the hit count in the inspector as shown in the book.:confused:
     

    Attached Files:

  46. DarkKnight

    DarkKnight

    Joined:
    Apr 2, 2011
    Posts:
    22
    Jose2090

    I had the same problem what I found was go to your Character in the hierarchy in the inspector you will see animation below that you will see animations.
    Now in you project manager click on models then character you will see 3 folders step , idle and catch
    drag and drop each folder to the elements each time you add 1 it will add a element.
     

    Attached Files:

  47. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Hi all,

    On page 153 , chapter 5:
    I try to put title scene at the bottom, it still works. Does it mean unity3.3.0f4 not care of the ordering of scene in build list ?
     
  48. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Hi all,

    On page 158,


    aGrid was already declared on top once, could
    "aGrid = new Array(); // Create a new , empty array at index i"
    be removed ?? Would this be declared twice?
     
    Last edited: May 5, 2011
  49. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
  50. Num_T

    Num_T

    Joined:
    Nov 17, 2010
    Posts:
    6
    No you cannot remove this. At the top you are creating a new array which you are storing in the variable aGrid. Further down you are creating an additional array each time through the for loop and storing within the first array. So as you go through the for loop you are repeatedly creating arrays and storing within the initial aGrid array, an array of arrays...

    The only thing that makes this confusing to get your head round initially I think is to understand that you aren't creating a new variable to refer to each of your new arrays. Instead you are only using your aGrid variable and getting to the, er... "1 level deeper arrays" by using the index numbers of your aGrid, hence aGrid...