Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

"Tic-Tac-Tut" Unity Genre Tutorial support thread.

Discussion in 'Assets and Asset Store' started by stimarco, Jun 11, 2012.

  1. stimarco

    stimarco

    Joined:
    Oct 17, 2007
    Posts:
    721
    For those with an interest in this sort of thing:

    The publisher dashboard tells me 185 people have downloaded the tutorial since it went free earlier this month, which is already more than the total number of purchases ever made since the first version was launched back in 2012. (No, there really isn't a lot of money in this! Judging by the Asset Store's "Top Free" stats, it seems Unity's own tutorials tend to be by far the most popular.)

    Also of interest is that no new reviews have appeared in about a year. This I find more interesting than the above: it seems client feedback is by far the trickiest problem with the App / Asset Store model and it's difficult to see how this can be improved without a radical rethink.
     
  2. nidhogge242

    nidhogge242

    Joined:
    Jul 21, 2016
    Posts:
    9
    Hey! Thanks for the tutorial. Trying to re-appropriate some of the stuff for my own game.

    I'm running into a problem where the GameInfo class is not being initialized in the GUIHandler.

    I've kept this part of the code

    Code (CSharp):
    1. public class GUIHandler : MonoBehaviour {
    2.  
    3.     private GameInfo gInfo;
    4.  
    5.     // Use this for initialization
    6.     void Start () {
    7.  
    8.         gInfo = new GameInfo();
    9.  
    10.         // sanity-check gInfo...
    11.         if (gInfo == null)
    12.         {
    13.             Debug.Log("ERROR: Could not initialise gInfo!");
    14.         }
    15.  
    16.     }
    And I do still have the GameInfo script where I've just added some other enums

    Code (CSharp):
    1. public class GameInfo : MonoBehaviour {
    2.  
    3.     public enum GameStates
    4.     {
    5.        
    6.         player1_card1,
    7.         player2_card1,
    8.         player1_card2,
    9.         player2_card2,
    10.  
    11.     } ;
    12.  
    13.     private GameStates _state = GameStates.player1_card1;
    14.  
    15.     public GameStates state
    16.     {
    17.         get
    18.         {
    19.             return _state;
    20.         }
    21.         set
    22.         {
    23.             _state = value;
    24.         }
    25.     }
    Any idea why?
     
  3. stimarco

    stimarco

    Joined:
    Oct 17, 2007
    Posts:
    721
    Hi nidhogge242,

    I'm not sure without seeing more of the code. Are you sure GUIHandler's Start() function is being called?

    In situations like these, I find it helps to track the flow of the program and make sure it's hitting all the right steps on the way. I'm a bit old school here: I tend to just spit out "I'm in [FUNCTION NAME]!" messages to the debug log (as shown below) and see which functions are being called, and when.

    For example, I would add the line below in the GUIHandler's Start() function:

    Code (CSharp):
    1. Debug.Log("GameInfo.Start() called.");
    I would place this immediately before the following line:

    Code (CSharp):
    1. gInfo = new GameInfo();
    If you see the "GameInfo.Start() called." message, then we know the problem is either somewhere inside Start(), or a problem with the GameInfo object definition itself.

    If you see that message and the one for the "sanity check" null value test, then the initialiser is being called, but it was unable to create the gInfo object. This usually means something's gone badly wrong, such as running out of memory. When this happens, it's time to go hunting for whichever object is currently allocating an insanely big blob of memory when it shouldn't be.

    If neither is appearing, the initialiser isn't being called at all and you need to track down the program flow and find out why. It could be a simple typo, or something more complicated. I can't help with that without a lot more code and context.
     
    Last edited: Jul 21, 2016
  4. nidhogge242

    nidhogge242

    Joined:
    Jul 21, 2016
    Posts:
    9
    Hey! Thanks for replying.

    When I put that line of code in the Start it does print to the console. I'm not sure what more to share unless I share the whole project. Not that it's very big at the moment. :)
     
  5. nidhogge242

    nidhogge242

    Joined:
    Jul 21, 2016
    Posts:
    9
    Here's the project if you have time and energy. https://dl.dropboxusercontent.com/u/1192419/cardgame.zip

    Been reading the earlier posts in this thread. It's a shame that you didn't get the response you wanted from the project. It's a novel approach to a tutorial which I quite like and wish there was more of.
     
  6. stimarco

    stimarco

    Joined:
    Oct 17, 2007
    Posts:
    721
    Thanks!

    I'm working on a more expanded version of the "Programming Primer" book as this seems to have elicited the most positive responses. I've restarted it a couple of times since this project was last updated, but the day-job means it'll be a while yet before I can finish it.

    I'm afraid I can't run Unity at the moment as my current computer is an old Surface Pro 2 that's seen better days and needs a new cooling fan – it makes expensive-sounding noises even when using a web browser and I need it for work, so all I can look through the code, but I can't run it.

    One possibility that occurred to me is that you do need to attach the GUIHandler script to a Unity object, like a prefab or some such. (It doesn't really matter what the object is, as long as it's present in the current Scene. If you don't do this, Unity never runs the script at all.

    You also need to attach the GameInfo script to the same object so that the GUIHandler script can 'see' it. (Ditto for any other scripts you want GUIHandler to reference.) Unity only runs scripts that are attached to something physically placed in the Scene.
     
  7. nidhogge242

    nidhogge242

    Joined:
    Jul 21, 2016
    Posts:
    9
    I tried this already. They're both attached to the same GameObject. I'm definitely not running out of memory.

    Actually, when looking at your project the GameInfo script isn't attached to the same GameObject (GUI). I can't see that it's attached to anything actually.
     
  8. stimarco

    stimarco

    Joined:
    Oct 17, 2007
    Posts:
    721
    That's odd, I could have sworn each script had to be in the Scene, or Unity won't run it. I may be misremembering; it's been a few months since I last looked at the project and my memory fades very quickly.

    Is the GameObject definitely in the Scene, not just in the list of Prefabs that can be added to it?

    Do any of the debug messages appear? If so, which ones?

    I'm not sure how else I can help as I can't even open Unity on this computer without making it buzz like a moped.
     
  9. nidhogge242

    nidhogge242

    Joined:
    Jul 21, 2016
    Posts:
    9
    I used to have a Surface Pro 2. It sounded like my lawn-mower before it died.

    Anyway, the GameObject is in the Scene. However, what I did now is just copy all the stuff from your GameInfo script into mine, changed the enums to the ones I'm using and just copied in your Player script as well (since the GameInfo was throwing errors without it).

    Now I don't get the debug logs! So it seems there is something in the GameInfo file that is needed for the initialization. So far so good. I'll just start stripping stuff from it until I find what I was missing before.

    Now, I'm not able to call the NextTurn() from a button like I was hoping to (the enum does not get flipped to the next one) but I'll follow your lead and put debug.log everywhere and see where it breaks.

    Thanks for the help so far!

    Edit: It actually does work! I put debuglogs into the if statments of the NextTurn() and it does cycle through the states, it's just my text-field that isn't updating for some reason. I can see why people get hooked on programming. It's like an ever-mutating murder mystery :)
     
    Last edited: Jul 21, 2016
  10. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    515
    @stimarco ,
    Hey man thanks for posting and making such a cool tutorial available. I came across your tutorial quite by accident while looking for a simple game to include in our KITT project. I was able to download your tutorial and convert a lot of it to the new UI in the latest version of unity, but I'm having a little difficulty trying to figure out how to get the buttons to work from a Voice interaction method.
    Basically looking to convert voice commands to place the appropriate X & O into the game grid and initiate a game between KITT and the player (KITT being the computer naturally)
     

    Attached Files:

  11. KamranAlex

    KamranAlex

    Joined:
    Dec 5, 2017
    Posts:
    1
    Hi sir, I have no idea about unity . But I need to make this game run.
    I've created a new project on unity and then opened up this assets on that new project.
    Here I can see the assets are documentation folder,previous version folder, 7 .cs file , a unity main scene file, a .png file and a BoardCell .prefab file.
    Is this all enough to run and play this game??

    If it is, then kindly tell me what I need to do next to run this game?
    I've selected th MainScene file and clicked play button but its not running.
    tell me how to run or play this on unity, please !!!
    thank you.