Search Unity

Official 2D Roguelike: Q&A

Discussion in 'Community Learning & Teaching' started by Matthew-Schell, Feb 10, 2015.

Thread Status:
Not open for further replies.
  1. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    You're missing a bunch of spaces. It should be "void BoardSetup" and "GameObject toInstantiate" and "GameObject instance"

    Please double check your code and make sure you are inserting spaces when necessary.
     
  2. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    If you'd like to give a thank you credit you should credit "Unity Technologies R+D Content Team" since I did not make this on my own. But thanks! You do not need a license to do this, the content is free to re-use and re-purpose.
     
  3. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    hey Andrew,

    Glad you found this helpful. Depending on the size of your game you probably will want to load and unload the scenes. There are a number of ways to do this but one way would be to save and reload them from disk. I would look at Mike Geig's live session here: https://unity3d.com/learn/tutorials...ining-archive/persistence-data-saving-loading

    Specifically he has a section on data serialization which you can use to serialize a class as binary data and then write and read that. In a personal project of mine I'm using that basic structure to write and read data about player unlocks and other data between sessions and I think it could work for your level data as well. I would just have a class that holds the level layout in an array or whatever you choose and then store that. Note that I haven't tested this approach, it's just an idea. Another option to look into would be JSON which I know people like but I don't personally have experience with.
     
    awillshire likes this.
  4. Dustin-Howard

    Dustin-Howard

    Joined:
    Mar 31, 2016
    Posts:
    12
    The asset message appears again, and it doesn't contain the 'accept' button when I clicked download.
    Maybe I'm doing this wrong. would someone at least give me a different download of the same assets and how to download it?
     
  5. awillshire

    awillshire

    Joined:
    Apr 29, 2014
    Posts:
    20
    Thanks again Matt! I'll check it out, looks exactly what I need. If I come up with some clean code patterns I'll post them back in to the forum.
    Cheers,
    Andrew.
     
  6. greatness

    greatness

    Joined:
    Feb 20, 2016
    Posts:
    199
    I'm on part 13 of the tutorial. I managed to make everything functional except for one thing. It is true that my enemy moves, but he only moves to the left or down-not up or right. Some code is below.

    Edit: Never mind. I set the transform.position of the enemy to an integer form. I have no idea why I did that.

    Enemy:

    Code (CSharp):
    1.  
    2.  
    3.  
    4. using UnityEngine;
    5. using System.Collections;
    6.  
    7.  
    8.     //Enemy inherits from MovingObject, our base class for objects that can move, Player also inherits from this.
    9.     public class Enemy : MovingObject
    10.     {
    11.         public int playerDamage;                            //The amount of food points to subtract from the player when attacking.
    12.  
    13.         private Animator animator;                          //Variable of type Animator to store a reference to the enemy's Animator component.
    14.         private Transform target;                           //Transform to attempt to move toward each turn.
    15.         private bool skipMove;                              //Boolean to determine whether or not enemy should skip a turn or move this turn.
    16.    
    17.  
    18.         //Start overrides the virtual Start function of the base class.
    19.         protected override void Start()
    20.         {
    21.         transform.position = new Vector2((int)transform.position.x, (int)transform.position.y);
    22.         isPlayer = false;
    23.             //Register this enemy with our instance of GameManager by adding it to a list of Enemy objects.
    24.             //This allows the GameManager to issue movement commands.
    25.             A_Game_Manager.instance.AddEnemy(this);
    26.    
    27.             //Get and store a reference to the attached Animator component.
    28.             animator = GetComponent<Animator>();
    29.      
    30.             //Find the Player GameObject using it's tag and store a reference to its transform component.
    31.             target = GameObject.FindGameObjectWithTag("Player").transform;
    32.  
    33.             //Call the start function of our base class MovingObject.
    34.             base.Start();
    35.         }
    36.  
    37.     public void EnemyMovement()
    38.     {
    39.         if (!A_Game_Manager.instance.playerTurns)
    40.         {
    41.             target = GameObject.FindGameObjectWithTag("Player").transform;
    42.             //Declare variables for X and Y axis move directions, these range from -1 to 1.
    43.             //These values allow us to choose between the cardinal directions: up, down, left and right.
    44.  
    45.             int xDir = 0, yDir = 0;
    46.  
    47.             //If the difference in positions is approximately zero (Epsilon) do the following:
    48.             if (Mathf.Abs(target.position.x - transform.position.x) < float.Epsilon)   yDir = target.position.y > transform.position.y ? 1 : - 1;
    49.             else xDir = target.position.x > transform.position.x ?  1 : - 1;
    50.  
    51.             //Check if target x position is greater than enemy's x position, if so set x direction to 1 (move right), if not set to -1 (move left).
    52.  
    53.  
    54.             //Call the AttemptMove function and pass in the generic parameter Player, because Enemy is moving and expecting to potentially encounter a Player
    55.          
    56.             AttemptMove<Player>(xDir,yDir);
    57.          
    58.  
    59.         }
    60.         else return;
    61. }
    62.     //Override the AttemptMove function of MovingObject to include functionality needed for Enemy to skip turns.
    63.     //See comments in MovingObject for more on how base AttemptMove function works.
    64.     protected override void AttemptMove<T>(int xDir, int yDir)
    65.     {
    66.         //Check if skipMove is true, if so set it to false and skip this turn.
    67.         if (skipMove)
    68.         {
    69.             skipMove = false;
    70.             return;
    71.  
    72.         }
    73.  
    74.         //Call the AttemptMove function from MovingObject.
    75.         base.AttemptMove<T>(xDir, yDir);
    76.      
    77.  
    78.         //Now that Enemy has moved, set skipMove to true to skip next move.
    79.         skipMove = true;
    80.     }
    81.  
    82.  
    83.  
    84.    
    85.  
    86.  
    87.         protected override void OnCantMove<T>(T component)
    88.         {
    89.         Player hitPlayer = component as Player;
    90.         hitPlayer.LoseFood(playerDamage);
    91.             animator.SetTrigger("enemyAttack");
    92.             SoundManager.instance.RandomizeMusic(SoundManager.instance.enemy1, SoundManager.instance.enemy2);
    93.         }
    94.     }
    95.  











    Game Manager:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine.UI;
    5.  
    6. public class A_Game_Manager : MonoBehaviour
    7. {
    8.     public float levelStartDelay = 2f;
    9.     public static A_Game_Manager instance = null;
    10.     public float turnDelay = 0.1f;
    11.     private BoardManager boardScript;
    12.     private int level = 1;
    13.     public int playerFoodPoints = 100;
    14.     [HideInInspector]
    15.     public bool playerTurns = true;
    16.  
    17.     private List<Enemy> enemies;
    18.     private bool enemiesMoving = false;
    19.     public Text textLevel;
    20.     private GameObject levelImage;
    21.     private bool boardSetUp = true;
    22.     private void OnLevelWasLoaded()
    23.     {
    24.         level++;
    25.         InitGame();
    26.     }
    27.  
    28.     private void Awake()
    29.     {
    30.         enabled = true;
    31.         if (instance == null)
    32.             instance = this;
    33.         else if (instance != this)
    34.             DestroyObject(gameObject);
    35.  
    36.         enemies = new List<Enemy>();
    37.  
    38.         DontDestroyOnLoad(gameObject);
    39.         boardScript = GetComponent<BoardManager>();
    40.         InitGame();
    41.     }
    42.  
    43.     void InitGame()
    44.     {
    45.         boardSetUp = true;
    46.         levelImage = GameObject.Find("Image");
    47.         textLevel = GameObject.Find("Level Text").GetComponent<Text>();
    48.         textLevel.text = "             Level " + level;
    49.         levelImage.SetActive(true);
    50.         enemies.Clear();
    51.         boardScript.SetUp(level);
    52.         Invoke("HideLevel", levelStartDelay);
    53.     }
    54.     private void HideLevel()
    55.     {
    56.         boardSetUp = false;
    57.         levelImage.SetActive(false);
    58.         textLevel.text = "";
    59.  
    60.     }
    61.     public void GameOver()
    62.     {
    63.         levelImage.SetActive(true);
    64.         textLevel.text = " After only " + level + " level(s), you DIED!";
    65.         SoundManager.instance.backgroundMusic.Stop();
    66.         SoundManager.instance.PlaySingle(SoundManager.instance.gameOverSound);
    67.         enabled = false;
    68.      
    69.      
    70.     }
    71.  
    72.     IEnumerator MoveEnemies()
    73.     {
    74.      
    75.         enemiesMoving = true;
    76.         yield return new WaitForSeconds(turnDelay);
    77.         if(enemies.Count==0)    yield return new WaitForSeconds(turnDelay);
    78.  
    79.         for (int i = 0; i < enemies.Count; i++)
    80.         {
    81.             enemies[i].EnemyMovement();
    82.             yield return new WaitForSeconds(enemies[i].moveTime);
    83.         }
    84.         playerTurns = true;
    85.         enemiesMoving = false;
    86.     }
    87.  
    88.     void Update()
    89.     {
    90.         if (playerTurns || enemiesMoving||boardSetUp)
    91.             return;
    92.         StartCoroutine(MoveEnemies());
    93.     }
    94.  
    95.     public void AddEnemy(Enemy script)
    96.     {
    97.         enemies.Add(script);
    98.     }
    99. }
    100.  
     
  7. greatness

    greatness

    Joined:
    Feb 20, 2016
    Posts:
    199
    I have another issue that I just realized. How come my game over sound doesn't play.
    Edit: I turned the soundEffects off at game over. why did i do that?
    Game Manager:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine.UI;
    5.  
    6. public class A_Game_Manager : MonoBehaviour
    7. {
    8.     public float levelStartDelay = 2f;
    9.     public static A_Game_Manager instance = null;
    10.     public float turnDelay = 0.1f;
    11.     private BoardManager boardScript;
    12.     private int level = 1;
    13.     public int playerFoodPoints = 100;
    14.     [HideInInspector]
    15.     public bool playerTurns = true;
    16.  
    17.     private List<Enemy> enemies;
    18.     private bool enemiesMoving = false;
    19.     public Text textLevel;
    20.     private GameObject levelImage;
    21.     private bool boardSetUp = true;
    22.     private void OnLevelWasLoaded()
    23.     {
    24.         level++;
    25.         InitGame();
    26.     }
    27.  
    28.     private void Awake()
    29.     {
    30.         enabled = true;
    31.         if (instance == null)
    32.             instance = this;
    33.         else if (instance != this)
    34.             DestroyObject(gameObject);
    35.  
    36.         enemies = new List<Enemy>();
    37.  
    38.         DontDestroyOnLoad(gameObject);
    39.         boardScript = GetComponent<BoardManager>();
    40.         InitGame();
    41.     }
    42.  
    43.     void InitGame()
    44.     {
    45.         boardSetUp = true;
    46.         levelImage = GameObject.Find("Image");
    47.         textLevel = GameObject.Find("Level Text").GetComponent<Text>();
    48.         textLevel.text = "             Level " + level;
    49.         levelImage.SetActive(true);
    50.         enemies.Clear();
    51.         boardScript.SetUp(level);
    52.         Invoke("HideLevel", levelStartDelay);
    53.     }
    54.     private void HideLevel()
    55.     {
    56.         boardSetUp = false;
    57.         levelImage.SetActive(false);
    58.         textLevel.text = "";
    59.  
    60.     }
    61.     public void GameOver()
    62.     {
    63.         levelImage.SetActive(true);
    64.         textLevel.text = " After only " + level + " level(s), you DIED!";
    65.         SoundManager.instance.backgroundMusic.Stop();
    66.         SoundManager.instance.PlaySingle(SoundManager.instance.gameOverSound);
    67.         enabled = false;
    68.  
    69.  
    70.     }
    71.  
    72.     IEnumerator MoveEnemies()
    73.     {
    74.      
    75.         enemiesMoving = true;
    76.         yield return new WaitForSeconds(turnDelay);
    77.         if(enemies.Count==0)    yield return new WaitForSeconds(turnDelay);
    78.  
    79.         for (int i = 0; i < enemies.Count; i++)
    80.         {
    81.             enemies[i].EnemyMovement();
    82.             yield return new WaitForSeconds(enemies[i].moveTime);
    83.         }
    84.         playerTurns = true;
    85.         enemiesMoving = false;
    86.     }
    87.  
    88.     void Update()
    89.     {
    90.         if (playerTurns || enemiesMoving||boardSetUp)
    91.             return;
    92.         StartCoroutine(MoveEnemies());
    93.     }
    94.  
    95.     public void AddEnemy(Enemy script)
    96.     {
    97.         enemies.Add(script);
    98.     }
    99. }
    100.  




    Sound Manager:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class SoundManager : MonoBehaviour {
    5.     public AudioSource soundEffects;
    6.     public AudioSource backgroundMusic;
    7.     public AudioClip moveSound1, moveSound2, eatSound1, eatSound2, drinkSound1, drinkSound2, gameOverSound, chopSound1, chopSound2, enemy1, enemy2;  //Audio clips to play. Two of each type to not make sound effects sound repetitive.
    8.  
    9.     public float lowPitch = .95f;
    10.     public float highPitch = 1.95f;
    11.     public static SoundManager instance = null;
    12.  
    13.     public void Awake()
    14.     {
    15.         if (instance == null) instance = this;
    16.         else if (instance != this) Destroy(gameObject);
    17.         DontDestroyOnLoad(gameObject);
    18.     }
    19.     public void PlaySingle(AudioClip clip)
    20.     {
    21.         soundEffects.clip = clip;
    22.         soundEffects.Play();
    23.     }
    24.  
    25.     public void RandomizeMusic(params AudioClip[] clips)
    26.     {
    27.         int randomIndex = Random.Range(0, clips.Length);
    28.         float randomPitch = Random.Range(lowPitch, highPitch);
    29.  
    30.         soundEffects.pitch = randomPitch;
    31.         soundEffects.clip = clips[randomIndex];
    32.         soundEffects.Play();
    33.  
    34.  
    35.     }
    36.  
    37.  
    38. }
    39.  
     
    Last edited: Apr 16, 2016
  8. greatness

    greatness

    Joined:
    Feb 20, 2016
    Posts:
    199
    I have just finished this tutorial. It works perfectly fine at the Unity editor but when I build it, things go strange. I start at level 2 and can't move. Any help out there?

    EDIT: Also, the enemy gets stuck in a wall. What is going on?
     
    Last edited: Apr 17, 2016
  9. Spajd

    Spajd

    Joined:
    Feb 15, 2016
    Posts:
    1
    Anybody have that error:
    It is after 9 lesson.
     

    Attached Files:

  10. greatness

    greatness

    Joined:
    Feb 20, 2016
    Posts:
    199
    I also have another problem. When I try to build for IOS, I see that there is no module downloaded. I can't build my game for IOS.
     
  11. LearningUn1ty

    LearningUn1ty

    Joined:
    Apr 17, 2016
    Posts:
    1
    Hello,
    Thanks for the good tutorial. I've been following the tutorial step by step so as to try understand the thought process of making this game. I've come across one error while following your steps and I would like to resolve it before moving forward. I am currently using version 5.3.2f1 of Unity, currently there is an update to version 5.3.4f1 but I don't want to upgrade till I resolve the error. The error happened after writing the Game Manager of the game, when creating the game loader. After following all the steps in the video and after creating the Loader script, Unity gives me this error
    This is the code of the Loader
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Loader : MonoBehaviour {
    5.  
    6.     public GameObject gameManager;
    7.  
    8.     void Awake ()
    9.     {
    10.         if (GameManager.instance == null)
    11.             Instantiate (gameManager);
    12.     }
    13. }
    I have done videos 1 to 5 without any editing or changing of the scripts or steps. I checked the loader code that is presented under the video number 5 and I can see there is more code added but in the video it is stated that the rest of the loader script will be presented in a later video so I didn't add the extra lines to my current code. Please tell me what I did wrong and what I can do to fix this error and move on. I have no experience coding in C# sorry.

    This is the GameManager code
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace Completed
    5. {
    6.     using System.Collections.Generic;       //Allows us to use Lists.
    7.  
    8.     public class GameManager : MonoBehaviour
    9.     {
    10.  
    11.         public static GameManager instance = null;              //Static instance of GameManager which allows it to be accessed by any other script.
    12.         private BoardManager boardScript;                       //Store a reference to our BoardManager which will set up the level.
    13.         private int level = 3;                                  //Current level number, expressed in game as "Day 1".
    14.    
    15.         //Awake is always called before any Start functions
    16.         void Awake()
    17.         {
    18.             //Check if instance already exists
    19.             if (instance == null)
    20.  
    21.                 //if not, set instance to this
    22.                 instance = this;
    23.  
    24.             //If instance already exists and it's not this:
    25.             else if (instance != this)
    26.  
    27.                 //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
    28.                 Destroy(gameObject);  
    29.  
    30.             //Sets this to not be destroyed when reloading scene
    31.             DontDestroyOnLoad(gameObject);
    32.  
    33.             //Get a component reference to the attached BoardManager script
    34.             boardScript = GetComponent<BoardManager>();
    35.  
    36.             //Call the InitGame function to initialize the first level
    37.             InitGame();
    38.         }
    39.  
    40.         //Initializes the game for each level.
    41.         void InitGame()
    42.         {
    43.             //Call the SetupScene function of the BoardManager script, pass it current level number.
    44.             boardScript.SetupScene(level);
    45.  
    46.         }
    47.  
    48.  
    49.  
    50.         //Update is called every frame.
    51.         void Update()
    52.         {
    53.  
    54.         }
    55.     }
    56. }
     
  12. technano

    technano

    Joined:
    Jan 13, 2016
    Posts:
    23
    So I just finished the video for writing the board manager and I have a whole ton of errors and I'm really not sure what's wrong with it? Here is the code I have:
    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections.Generic;
    4. using Random = UnityEngine.Random;
    5.  
    6. public class BoardManager : MonoBehaviour
    7. {
    8.  
    9.     [Serializable]
    10.     public class Count
    11.     {
    12.         public int minimum;
    13.         public int maximum;
    14.  
    15.         public Count(int min, int max)
    16.         {
    17.             minimum = min;
    18.             maximum = max;
    19.         }
    20.     }
    21.  
    22.     public int columns = 8;
    23.     public int rows = 8;
    24.     public Count wallCount = new Count (5, 9);
    25.     public Count foodCount = new Count (1, 6);
    26.     public GameObject exit;
    27.     public GameObject[] floorTiles;
    28.     public GameObject[] wallTiles;
    29.     public GameObject[] foodTiles;
    30.     public GameObject[] enemyTiles;
    31.     public GameObject[] outerWallTiles;
    32.  
    33.     private Transform boardHolder;
    34.     private List <Vector3> gridPositions = new List<Vector3> ();
    35.  
    36.     void InitialiseList()
    37.     {
    38.         gridPositions.Clear ();
    39.  
    40.         for (int x = 1; x < columns - 1; x++)
    41.         {
    42.             for (int y = 1; y < rows - 1; y++)
    43.             {
    44.                 gridPositions.Add (new Vector3 (x, y, 0f));
    45.             }
    46.         }
    47.     }
    48.  
    49.     void BoardSetUp()
    50.     {
    51.         boardHolder = new GameObject ("Board").transform;
    52.  
    53.         for (int x = -1; x < columns + 1; x++)
    54.         {
    55.             for (int y = -1; y < rows + 1; y++)
    56.             {
    57.                 GameObject toInstantiate = floorTiles [Random.Range (0, floorTiles.Length)];
    58.                 if (x == -1 || x == columns || y == -1 || y == rows)
    59.                     toInstantiate = outerWallTiles [Random.Range (0, outerWallTiles.Length)];
    60.  
    61.                 GameObject instance = Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaturnion.identity) as GameObject;
    62.  
    63.                 instance.transform.SetParent (boardHolder);
    64.             }
    65.         }
    66.     }
    67.  
    68.     Vector3 RandomPosition()
    69.     {
    70.         int randomIndex = Random.Range (0, gridPositions.Count);
    71.         Vector3 randomPosition = gridPositions [randomIndex];
    72.         gridPositions.RemoveAt (randomIndex);
    73.         return RandomPosition;
    74.     }
    75.  
    76.     void layoutObjectAtRandom (GameObject[] tileArray, int min, int max)
    77.     {
    78.         int objectCount = Random.Range (minimum, maximum + 1);
    79.         for (int i = 0; i < objectCount; i++)
    80.         {
    81.             Vector3 randomPosition = RandomPosition ();
    82.             GameObject tileChoice = tileArray [Random.Range (0, tileArray.Length)];
    83.             Instantiate (tileChoice, randomPosition, Quaternion.identity);
    84.         }
    85.     }
    86.     public void SetupScene (int level)
    87.     {
    88.         BoardSetup ();
    89.         InitialiseList ();
    90.         layoutObjectAtRandom (wallTiles, wallCount.minimum, wallCount.maximum);
    91.         layoutObjectAtRandom (foodTiles, foodCount.minimum, foodCount.maximum);
    92.         int enemyCount = (int)Mathf.log (level, 2f);
    93.         layoutObjectAtRandom (enemyTiles, enemyCount, enemyCount);
    94.         Instantiate (exit, new Vector3 (columns - 1, rows - 1, 0f), Quaternion.identity);
    95.     }
    96.     }
    I have a feeling it might be the latest update to Unity, but a lot of keywords won't highlight like they usually do. things like GameObject[], Quaternion and things like those keywords will not highlight! I also feel like it's something at the top, one of the using code segments. Please help! thank you!
     
  13. greatness

    greatness

    Joined:
    Feb 20, 2016
    Posts:
    199

    Well, it would be more helpful if you would post the errors that your compiler is telling you.
     
  14. technano

    technano

    Joined:
    Jan 13, 2016
    Posts:
    23
    Sorry, I forgot to do that. But I spent more time looking at my code and all the errors were syntax errors. I was misspelling most of the keywords. But I'm still having the problem with words not being highlighted and there is this other problem where let's say I type M to start typing Mathf that word doesn't show up on the completion drop down list and therefore doesn't get highlighted. Sorry again for not showing the errors before.
     
  15. Dustin-Howard

    Dustin-Howard

    Joined:
    Mar 31, 2016
    Posts:
    12
    I tried to download the assets even from the website but still no luck
     
  16. Sloan57

    Sloan57

    Joined:
    Mar 5, 2016
    Posts:
    7
    Hello Dustin,

    I have had the same problem, and I solved it :)
    Maybe I can help you.
    You said you have not "Accept" button and I thought too BUT I resized my window and the "Accept" button was at the end of window :p

    See you ;)

    PS: sorry for my bad english, I'm french^^
     
  17. Dustin-Howard

    Dustin-Howard

    Joined:
    Mar 31, 2016
    Posts:
    12
    WOW
    OK
    That's the end of that problem. Thank you so much
    Now I can actually do the tutorial
     
  18. Nadesican

    Nadesican

    Joined:
    Sep 8, 2013
    Posts:
    3
    Hey there! I'm having a slight problem with the player - he isn't there. I'm running the most updated version of Unity.

    I've noticed that when previewing his animations, he appears in the scene view, but not the game view. This becomes important around step 11 when the playable game should be view able. What I end up with is a player visible on the scene, in proper position, but not in the game itself - though everything else is.

    I've experimented and noticed that the invisible player is able to move once, and potentially destroy a wall near that second spot.. but after that he can't move and is still quite invisible. For what it's worth, I've replaced the 'loadlevel' with the more recent 'loadscene' without any hiccups.

    I've noticed that the player tile doesn't seem to be called anywhere.. could that be the problem?
     
  19. jsbryan1

    jsbryan1

    Joined:
    Feb 16, 2016
    Posts:
    4
    Hello! Between video 4/5 if you use the "namespace" tag included in the sample scripts, Unity will tell you that the tag already exists in one of the two scripts and it will cause an error.
     
  20. virjanand

    virjanand

    Joined:
    Nov 12, 2015
    Posts:
    1
    Thanks for the tutorial! I'm following it now and am almost at the end. Just finished the sound video and wanted to try and make a build. The game is working fine in the editor, but when I build it it skips level 1 and 3. You end up in level 4 with 0 food. I've tried to build the completed version and this has the same issue. I built it both in the Mac version as well as in webPlayer version and they had the same issue.

    I've also tried a developer build, but don't really know how to use that, yet. I hope someone can help me with this issue. It's really weird because in the editor it works just fine.
     
  21. Alucardko

    Alucardko

    Joined:
    Apr 28, 2016
    Posts:
    1
    I have a error, somebody can help me? I´m in part 5

    Error
    Script
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GameManager : MonoBehaviour {
    5.  
    6.     public BoardManager boardScript;
    7.  
    8.     private int level = 3;
    9.  
    10.  
    11.     // Use this for initialization
    12.     void Awake ()
    13.     {
    14.         boardScript = GetComponent<BoardManager>();
    15.         InitGame();
    16.     }
    17.  
    18.     void InitGame()
    19.     {
    20.         boardScript.SetupScene(level);
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update () {
    25.  
    26.     }
    27. }
     
  22. Hannt

    Hannt

    Joined:
    May 3, 2016
    Posts:
    1
    How should I update the code:

    Code (CSharp):
    1.   private void Restart ()
    2.         {        
    3.             Application.LoadLevel (Application.loadedLevel);
    4.         }
     
  23. Dustin-Howard

    Dustin-Howard

    Joined:
    Mar 31, 2016
    Posts:
    12
    upload_2016-5-11_17-11-9.png

    help plzzz... upload_2016-5-11_17-11-9.png
     
  24. AstroUrsus

    AstroUrsus

    Joined:
    May 15, 2016
    Posts:
    1
    Hi I've been following this tutorial for a while now I'm currently on 3.06. and throughout the process I've only had the player show up in the game tab when i try to have it play. The rest of the screen was blue. I was wondering if there could be anything specific wrong with it. I mean all of the animations for the player work, but only the player shows there's no floor or walls.
     
  25. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Ill have a work through the tutorial again tomorrow morning, as its been a while since ive done it, and help out where I can until Matt gets back.
     
  26. TC21

    TC21

    Joined:
    May 19, 2016
    Posts:
    7
    I tried doing this tutorial 4 times exactly as in the videos but for some unknown reason i get many errors with the script and with some other stuff!Later I might post some images about the problem I have.
     
  27. TC21

    TC21

    Joined:
    May 19, 2016
    Posts:
    7
    I tried to redownload the project files and import them to a new project I had the same problem!
    Maybe is it because the files weren't downloaded correctly ? because when i try to download the project files the download stays at XX% forever!


    All these happens when I import the downloaded project! (The first time i didn't had this problem,but now it always there)

    Help Please!!! :(
     
    Last edited: May 19, 2016
  28. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Might be worth a shot, deleting the downloaded package (bin icon) and then trying to redownload again from the start.
    Also, just check that your logged into the asset store just in case, maybe log out and back in.
    cant think of anything else at the moment that might help.

    might be getting import errors due to partial or corrupted downloads possibly, or a runtime error behind the scenes.
    What version of Windows do you have out of curiosity?
     
    Last edited: May 19, 2016
    TC21 likes this.
  29. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Within your Game Manager prefab, check the BoardManager component.
    Do you have all the arrays for walls and floors populated?

    when you play the game, do you get the board showing in the scene heirarchy, and is there anything childed to it, as in any wall/food/floor tiles?
     
  30. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Hi,

    Looks like it cannot find the BoardManager Class.

    Can i ask, are you using the BoardManager script that was in the completed folder?

    Its just that this is within a different namespace so that it doesn't throw errors when you are working through the tutorial.

    in your board manager that you are using to work through the tutorial, do you have this at the top?
    Code (CSharp):
    1. namespace Completed
    2. {
    if so, just comment out that line, and remember to comment out the corresponding closing ' }' at the very bottom of the script.

    see how you get on, if thats not it, can you post your BoardManager script please, just for a look.
     
  31. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
  32. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Have a look at your BoardManager script.
    check that the spelling and case for your SetupScene function is correct.

    if thats not it, can you post your BoardManager script please (using code tags please to make it easier to read)
     
  33. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Think it may be related to a bug that was found, and has been logged. see the following post from Matt, and a workaround in its following post.
    http://forum.unity3d.com/threads/2d-roguelike-q-a.297180/page-12#post-2448963

    hope that helps in the meantime.
     
  34. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    is the player set to use the correct layer?
    when you run the game, does the player show in the scene heirarchy?
     
  35. TC21

    TC21

    Joined:
    May 19, 2016
    Posts:
    7
    My PC runs Windows 10 Pro 32-Bit Version!
    Also where is the location were the downloaded files are?
     
    Last edited: May 19, 2016
  36. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    TC21 likes this.
  37. TC21

    TC21

    Joined:
    May 19, 2016
    Posts:
    7
  38. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Not sure bud, but while we wait for the guys when they get time, know theyre busy with Unite, but I'll have another dig around tomorrow to see what I can find out to get you back on track.

    Either that or I've just restarted this tute to refresh memory, so i can pop my bare bones project online to try and at least get you going in the mean time, if we have to go down that route in the interim.
     
    TC21 likes this.
  39. TC21

    TC21

    Joined:
    May 19, 2016
    Posts:
    7
    Even with the complete project you sent me yesterday does not even work like the others! :(


    I get this errors when i try to open the project you sent me!! :confused:
     
  40. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    ah, thats cos i deleted the Library and temp folders pre upload to save hosting space.

    if you click continue, as it looks like you have it should recreate these folders I believe.
    the Yellow triangles you are getting, are warnings, more a consideration as opposed to a show stopper error.

    doesnt look like you are getting the audio import errors tho, so it may have been a corruption somewhere along the line.

    Have a try and loading up the Scene in the completed folder and playing, see if it works.
     
    TC21 likes this.
  41. TC21

    TC21

    Joined:
    May 19, 2016
    Posts:
    7
    Sorry I forgot to sent the 3rd image where the errors where!As you can see there are 17 of them!I can paly at all the game but either way the warnings about the script where it says to use SceneManager.LoadScene instead of UnityEngine.Application.LoadLevel ,does it cause any problems?
    http://forum.unity3d.com/threads/unityengine-application-loadlevel-int-is-obsolete.372915/
     
  42. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Sorry man, dont know what else to think about, hopefully a better and workable solution will come to you soon to get you back on track from the guys.
     
  43. Awufl

    Awufl

    Joined:
    May 24, 2016
    Posts:
    1
    Hi guys,

    I have a problem with my Player script. I get the error warning 'The type or namespace 'Wall' could not be found ( are you missing a using directive or an assembly reference?', and I can't fix it to save my life.

    This is the player code I have:

    Code (CSharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. namespace Completed
    7. {
    8. public class Player:MovingObject
    9. {
    10.  
    11.     public int wallDamage = 1;
    12.     public int pointsPerFood = 10;
    13.     public int pointsPerSoda = 20;
    14.     public float restartLevelDelay = 1f;
    15.  
    16.     private Animator animator;
    17.     private int food;
    18.  
    19.  
    20.     // Use this for initialization
    21.     protected override void Start ()
    22.     {
    23.         animator = GetComponent<Animator> ();
    24.  
    25.         food = GameManager.instance.playerFoodPoints;
    26.  
    27.         base.Start ();
    28.    
    29.     }
    30.  
    31.     private void OnDisable()
    32.     {
    33.         GameManager.instance.playerFoodPoints = food;
    34.     }
    35.     // Update is called once per frame
    36.     void Update ()
    37.     {
    38.         if (!GameManager.instance.playersTurn)
    39.             return;
    40.  
    41.         int horizontal = 0;
    42.         int vertical = 0;
    43.  
    44.         horizontal = (int)Input.GetAxisRaw ("Horizontal");
    45.         vertical = (int)Input.GetAxisRaw ("Vertical");
    46.  
    47.         if (horizontal != 0)
    48.             vertical = 0;
    49.  
    50.             if (horizontal != 0 || vertical != 0)
    51.             {
    52.                 AttemptMove<Wall> (horizontal, vertical);
    53.             }
    54.     }
    55.  
    56.     protected override void AttemptMove <T> (int xDir, int yDir)
    57.     {
    58.         food--;
    59.  
    60.         base.AttemptMove<T> (xDir, yDir);
    61.  
    62.         RaycastHit2D hit;
    63.  
    64.         CheckIfGameOver ();
    65.  
    66.         GameManager.instance.GameOver ();
    67.     }
    68.  
    69.     private void OnTriggerEnter2D (Collider2D other)
    70.     {
    71.         if (other.tag == "Exit") {
    72.             Invoke ("Restart", restartLevelDelay);
    73.             enabled = false;
    74.         }
    75.         else if (other.tag == "Food")
    76.         {
    77.             food += pointsPerFood;
    78.             other.gameObject.SetActive(false);
    79.         }
    80.         else if (other.tag == "Soda")
    81.         {
    82.             food += pointsPerSoda;
    83.             other.gameObject.SetActive(false);
    84.         }
    85.     }
    86.  
    87.     protected override void OnCantMove <T> (T component)
    88.     {
    89.         Wall hitWall = component as Wall;
    90.         hitWall.DamageWall (wallDamage);
    91.         animator.SetTrigger ("playerChop");
    92.     }
    93.  
    94.     private void Restart()
    95.     {
    96.         Application.LoadLevel (Application.loadedLevel);
    97.     }
    98.  
    99.     public void LoseFood (int loss)
    100.     {
    101.         animator.SetTrigger("playerHit");
    102.         food -= loss;
    103.         CheckIfGameOver();
    104.     }
    105.  
    106.  
    107.     private void CheckIfGameOver()
    108.     {
    109.         if (food <= 0)
    110.             GameManager.instance.GameOver ();
    111.     }
    112. }
    113. }
     
  44. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening,

    If you can please, can you say what video / step in the tutorial you are currently working through.

    I see you are using the scripts that were in the Completed folder. are you using all of the scripts or are you typing some in as well?

    Just wondering, the 'Wall' reference that its looking for as its looking for a type which in this case is a script and class we have called Wall.cs . do you have a Wall.cs script created? depending what lesson you are on.
    If you have the script, can you see if the class name at the top of it matches the filename of the script, and that they are both Capitalised 'Wall'.

    Also, something else to bear in mind, you have this script within the Completed namespace (top of the script). this was put in I believe to separate the completed scripts, and the scripts that you will be working through so they wouldnt conflict in the editor as they would be in two different namespaces.
     
  45. rehtse_studio

    rehtse_studio

    Joined:
    Jul 25, 2013
    Posts:
    24
    Is there a way I can use the chop animation to actually hit the enemy? If yes how can I incorporate it on my script
     
  46. Tachylyte

    Tachylyte

    Joined:
    May 28, 2016
    Posts:
    1
    This is a great tutorial, as far as I've gotten!

    One bit of feedback, though, for future tutorials: Although you do provide completed versions of the scripts, some people might prefer to slow things down a bit (you go through the code quite quickly, which is great for some people, but not for everybody!) and type it all themselves to get a thorough understanding of what you're doing... which is fine, except that when we pause the video, often the code that you just created is way at the bottom of the video window, and therefore is covered up by the video player's controls while it is paused! Ideally, the current code work area would be in the middle of the screen so we can ponder it while the video is paused, rather than having to go hunt through the completed code files to actually see the code, or progress the video to later on so we can see some line we wanted to look at more closely.
     
  47. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    as a side note, remember that most of the videos have the completed scripts below the video on the page.
    If your watching on the Unity learn / tutorial site that is, as opposed to youtube.
     
  48. broodj3

    broodj3

    Joined:
    May 29, 2016
    Posts:
    1
    Hi, I've completed the tutorial and followed it down to the T and the floaty bits above the I's. The problem I've got is that when I run/test the game, none of the walls are actually blocking my movement? They block the enemy movement, but I can still walk wherever I want within the design space (outside the walls included).

    Also, any idea what the default attack keybind is? There's no mention of it at all in the tutorial so I've no idea how to test the attack animation on the wall/zombies.
     
  49. takewing_14

    takewing_14

    Joined:
    Sep 23, 2015
    Posts:
    6
    Have any of you experimented with modifications of the "Day" screens between levels? For the project I'm working on, I'm using the Roguelike template because I love the random level generation. But I need specific text in between every level, and it has to be different with each level. How might I achieve this? Thanks in advance!
     
  50. Mergod

    Mergod

    Joined:
    Jun 1, 2016
    Posts:
    1
    I've been having this same problem as well.

    EDIT: As an additional F.Y.I this causes no console errors of any kind for me.

    EDIT 2: On a whim i commented out check if game over in the player script under attempt move. This allowed me to move without dying instantly, which was great. However, the first time the player gets attacked by an enemy it still caused instant game over which confused me even further. Upon commenting out the hitPlayer.LoseFood , the monsters still play hit anim and sfx but no longer kills or deals damage to the player. Although the player still plays hit noise and anim. Then if i undo that and just comment out CheckIfGameOver(); under LoseFood in the player script the damage is done normally from the monsters and walking but no death is incurred at <=0. I get the feeling that the answer to this is just staring at me right in the face and I can't pick up on it.


    EDIT 3: Upon Debugging, anything that had to do with food subtraction is being subtracted normally. However, if the lines of script that check if game over aren't commented out , anything that has a CheckIfGameOver is just calling gameover (one step still subtracts 1 food in the console when debugged but causes game over, same with the enemies damage, get hit lose 10,20 food still have leftover food points , die anyway)




    At the end of the adding music and sound effects tutorial when the video asks you to play test, it simply causes game over on first move. The thing that is most frustrating is that before adding the audio the game ran flawlessly. Ive been through this entire thread and the only help I've been able to dredge is that somehow the players food is getting set to zero on first move. Ive fiddled around with several things in the scripts. the game manager in the inspector is correctly set to 100 as is the script referencing it. I even, at one point (in an act of desperation) set the food game over requirements to if (food >= 0) and then set the players starting food to -1 to see if something was being subtracted, or just set to zero. This still resulted in game over on first move. However this made it very clear that something somewhere is setting the players food points to zero on move. This of course leads me to believe there is something up with the AttemptMove function. However the only thing added to this before it stopped working properly that seems like a suspect is

    Code (CSharp):
    1. RaycastHit2D hit;
    2.         if (Move (xDir, yDir, out hit))
    3.         {
    4.             SoundManager.instance.RandomizeSfx(moveSound1, moveSound2);
    5.         }



    Here is the entire player script
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class Player : MovingObject {
    6.  
    7.     public int wallDamage = 1;
    8.     public int pointsPerFood = 10;
    9.     public int pointsPerSoda = 20;
    10.     public float restartLevelDelay = 1f;
    11.     public Text foodText;
    12.     public AudioClip moveSound1;
    13.     public AudioClip moveSound2;
    14.     public AudioClip eatSound1;
    15.     public AudioClip eatSound2;
    16.     public AudioClip drinkSound1;
    17.     public AudioClip drinkSound2;
    18.     public AudioClip gameOverSound;
    19.  
    20.     private Animator animator;
    21.     private int food;
    22.  
    23.  
    24.  
    25.     // Use this for initialization
    26.     protected override void Start ()
    27.     {
    28.  
    29.         animator = GetComponent<Animator> ();
    30.  
    31.         food = GameManager.instance.playerFoodPoints;
    32.  
    33.         foodText.text = "Food: " + food;
    34.  
    35.         base.Start ();
    36.     }
    37.  
    38.  
    39.     private void OnDisable()
    40.     {
    41.         GameManager.instance.playerFoodPoints = food;
    42.     }
    43.     // Update is called once per frame
    44.  
    45.     void Update ()
    46.     {
    47.         if (!GameManager.instance.playersTurn) return;
    48.  
    49.         int horizontal = 0;
    50.         int vertical = 0;
    51.  
    52.         horizontal = (int) Input.GetAxisRaw("Horizontal");
    53.         vertical = (int) Input.GetAxisRaw("Vertical");
    54.  
    55.         if (horizontal != 0)
    56.             vertical = 0;
    57.  
    58.  
    59.         if (horizontal != 0 || vertical != 0)
    60.             AttemptMove<Wall> (horizontal, vertical);
    61.     }
    62.  
    63.     protected override void AttemptMove <T> (int xDir, int yDir)
    64.     {
    65.         food--;
    66.  
    67.         foodText.text = "Food: " + food;
    68.  
    69.         base.AttemptMove <T> (xDir, yDir);
    70.  
    71.         RaycastHit2D hit;
    72.         if (Move (xDir, yDir, out hit))
    73.         {
    74.             SoundManager.instance.RandomizeSfx(moveSound1, moveSound2);
    75.         }
    76.  
    77.         CheckIfGameOver ();
    78.  
    79.         GameManager.instance.playersTurn = false;
    80.     }
    81.  
    82.  
    83.     private void OnTriggerEnter2D (Collider2D other)
    84.     {
    85.  
    86.         if (other.tag == "Exit")
    87.         {
    88.             Invoke ("Restart", restartLevelDelay);
    89.             enabled = false;
    90.         }
    91.         else if(other.tag == "Food")
    92.         {
    93.             food += pointsPerFood;
    94.             foodText.text = "+" + pointsPerFood + " Food: " + food;
    95.             SoundManager.instance.RandomizeSfx (eatSound1, eatSound2);
    96.             other.gameObject.SetActive(false);
    97.         }
    98.         else if(other.tag == "Soda")
    99.         {
    100.             food += pointsPerSoda;
    101.             foodText.text = "+" + pointsPerSoda + " Food: " + food;
    102.             SoundManager.instance.RandomizeSfx (drinkSound1, drinkSound2);
    103.             other.gameObject.SetActive(false);
    104.         }
    105.     }
    106.     protected override void OnCantMove <T> (T component)
    107.     {
    108.         Wall hitWall = component as Wall;
    109.         hitWall.DamageWall (wallDamage);
    110.         animator.SetTrigger ("PlayerChop");
    111.     }
    112.  
    113.     private void Restart()
    114.     {
    115.         Application.LoadLevel (Application.loadedLevel);
    116.     }
    117.  
    118.     public void LoseFood (int loss)
    119.     {
    120.         animator.SetTrigger ("PlayerHit");
    121.         food -= loss;
    122.         foodText.text = "-" + loss + " Food: " + food;
    123.         CheckIfGameOver ();
    124.     }
    125.  
    126.     private void CheckIfGameOver()
    127.     {
    128.         if (food <= 0)
    129.             SoundManager.instance.PlaySingle (gameOverSound);
    130.             SoundManager.instance.musicSource.Stop ();
    131.             GameManager.instance.GameOver();
    132.  
    133.     }
    134.  
    135.  
    136. }
    137.  


    and my GameManager just in case its helpful



    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine.UI;
    5.  
    6. public class GameManager : MonoBehaviour {
    7.  
    8.     public float  levelStartDelay = 2f;
    9.     public float turnDelay = .1f;
    10.     public static GameManager instance = null;
    11.     public BoardManager boardScript;
    12.     public  int playerFoodPoints = 100;
    13.     [HideInInspector] public bool playersTurn = true;
    14.  
    15.     private Text levelText;
    16.     private GameObject levelImage;
    17.     private int level = 1;
    18.     private List<Enemy> enemies;
    19.     private bool enemiesMoving;
    20.     private bool doingSetup;
    21.  
    22.     void Awake()
    23.     {
    24.         if (instance == null)
    25.             instance = this;
    26.         else if (instance != this)
    27.             Destroy(gameObject);
    28.  
    29.         DontDestroyOnLoad (gameObject);
    30.         enemies = new List<Enemy> ();
    31.         boardScript = GetComponent<BoardManager> ();
    32.         InitGame();
    33.     }
    34.  
    35.     private void OnLevelWasLoaded (int index)
    36.     {
    37.         level++;
    38.  
    39.         InitGame ();
    40.     }
    41.  
    42.     void InitGame()
    43.     {
    44.         doingSetup = true;
    45.  
    46.         levelImage = GameObject.Find ("LevelImage");
    47.         levelText = GameObject.Find ("LevelText").GetComponent<Text> ();
    48.         levelText.text = "Day " + level;
    49.         levelImage.SetActive (true);
    50.         Invoke ("HideLevelImage", levelStartDelay);
    51.  
    52.         enemies.Clear ();
    53.         boardScript.SetupScene(level);
    54.     }
    55.  
    56.     private void HideLevelImage()
    57.     {
    58.         levelImage.SetActive (false);
    59.         doingSetup = false;
    60.     }
    61.  
    62.     public void GameOver()
    63.     {
    64.         levelText.text = "After " + level + " days, you starved";
    65.         levelImage.SetActive (true);
    66.         enabled = false;
    67.     }
    68.  
    69.  
    70.     void Update ()
    71.     {
    72.         if (playersTurn || enemiesMoving || doingSetup)
    73.             return;
    74.  
    75.         StartCoroutine (MoveEnemies ());
    76.     }
    77.  
    78.     public void AddEnemyToList(Enemy script)
    79.     {
    80.         enemies.Add (script);
    81.     }
    82.  
    83.     IEnumerator MoveEnemies()
    84.     {
    85.         enemiesMoving = true;
    86.         yield return new WaitForSeconds(turnDelay);
    87.         if (enemies.Count == 0)
    88.         {
    89.             yield return new WaitForSeconds (turnDelay);
    90.         }
    91.         for (int i = 0; i < enemies.Count; i++)
    92.         {
    93.             enemies[i].MoveEnemy ();
    94.             yield return new WaitForSeconds (enemies [i].moveTime);
    95.         }
    96.  
    97.         playersTurn = true;
    98.         enemiesMoving = false;
    99.  
    100.     }
    101.  
    102. }
    103.  
    Also, love these tutorials and how much work it takes. Thanks a lot!

    Big thanks to anyone who has any insight on this matter as well.
     
    Last edited: Jun 10, 2016
Thread Status:
Not open for further replies.