Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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. JamesPromIII

    JamesPromIII

    Joined:
    Sep 15, 2015
    Posts:
    2
    Error2.jpg Error.jpg Hey I've been using Unity for about 9 months now and I have a question on THIS tutorial. Why isn't my game board coming up after I do all of the coding? I used the scripts in the completed folder, not a big fan of the coding part although I do watch them. Here is a screenshot of my issue, any help would be much obliged.
     
  2. skullscars

    skullscars

    Joined:
    Sep 16, 2015
    Posts:
    1
    Hello, firstly just want to say that this tutorial is probably the best one there. Not only because of how much I learnt, but how easy you can expand upon it. There are so many opportunities to take this game and improve upon it and make it your own. I'm planning on making level generation better and adding multiple-room levels and such (basically turn it into a bigger game).

    I have a problem though.... A really weird bug actually. After 2 levels, all my food goes away upon entering level 3. But it calls it level 2 again. Then I die, and it says I died on level 5. If I tweak the code so I don't need food to walk, then the level numbers are all jumbled up.
    My code looks almost like a carbon copy of yours, so I have no idea how this is happening.
    Do any of you have any suggestions as to what it might be? Thanks a bunch in advance.
     
  3. Mohobie

    Mohobie

    Joined:
    Sep 5, 2015
    Posts:
    13
    Thank you I will take a look at the raycast again.
     
    Matthew-Schell likes this.
  4. TaikeiNoYuurei

    TaikeiNoYuurei

    Joined:
    Sep 20, 2015
    Posts:
    3
    I'm having a very very weird bug. I was just about to start on the 'adding sound' portion of the tutorial, when I figured I'd make sure my game was working properly. Seemed to be running fine, and then I suddenly merged with a zombie with both of us trying to move to the same space. It didn't happen 100% of the time, but it happened fairly regularly. Similarly I noticed with 100% frequency, that if I was standing down-left of a zombie when it was both of our turns to move, and I moved right, so I'd be directly beneath him, he would move left, trying to get to where I was instead of where I had moved to.

    Anyway, I played around with things for a while, and eventually found that the issue was that the game wasn't putting in a delay between me moving and the zombies trying to move. So, played around with the code a bit more, and that's where I got into the weird part of my bug. For some reason, the line
    Code (CSharp):
    1. yield return new WaitForSeconds(turnDelay);
    down in my MoveEnemies coroutine wasn't pulling my turnDelay variable. If I set the number as 0.1f directly in the WaitForSeconds it would work properly. If I set it as WaitForSeconds(1) it would work properly. And if I changed turnDelay to an int that was equal to 1 it would work properly. For some reason it only seems to not pull it properly if it is float, even thought WaitForSeconds works fine with a float put in directly.

    Edit: I should note that putting in the delay directly doesn't seem to entirely fix the zombies moving sideways instead of attacking me if I move in from the sides, but I haven't gotten the 'move onto the same space' bug since then. Seems the zombies also aren't waiting for my movement to finish before they start their own, but that is a different problem.

    Edit2: It looks like the issues are present in the completed game as provided in the assets as well. The turnDelay variable isn't getting pulled at all (I tried changing it to 2.0f just to check) and they still move sideways (and the turns aren't being delayed seemingly at all, much less 2 seconds), which indicates they are trying to move before the player has completed his own movement somehow. I looked over the code and I can't seem to find any reason for this, since the playerTurn boolean should remain true until the movement is finished based on how I read the code. I couldn't replicate the 'move to the same square' problem again, but it seemed to get harder to replicate the more often I tried it regardless.

    Edit3: Bit more testing, and yes, the enemies aren't waiting for player movement to finish before trying to move themselves, this is causing them to generally target the player at his prior location instead of his current one, and occasionally causing the CanMove method to return that the player isn't in the way because he hasn't fully moved into the position yet. I think this might be because SmoothMovement is a coroutine, and thus (if my knowledge is correct) allows the rest of the code to run while it does its own thing, thus meaning that the Move method can finish before the SmoothMovement finishes actually moving the character, thus causing the pathing and collision issues. I think I'm going to fix it by putting the turn delay in the while loop for enemy movement before the actual enemy movement and ensuring that it matches the time for the SmoothMovement to finish. Still hoping to figure out the original issue of why WaitForSeconds isn't pulling turnDelay at all when it is a float.


    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 = 0.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.     // Use this for initialization
    23.     void Awake () {
    24.         if (instance == null)
    25.             instance = this;
    26.         else if (instance != this)
    27.             Destroy (gameObject);
    28.         DontDestroyOnLoad(gameObject);
    29.         enemies = new List<Enemy>();
    30.         boardScript = GetComponent<BoardManager>();
    31.         InitGame();
    32.     }
    33.  
    34.     private void OnLevelWasLoaded (int index)
    35.     {
    36.         level++;
    37.  
    38.         InitGame ();
    39.     }
    40.  
    41.     void InitGame()
    42.     {
    43.         doingSetup = true;
    44.  
    45.         levelImage = GameObject.Find("LevelImage");
    46.         levelText = GameObject.Find("LevelText").GetComponent<Text>();
    47.         levelText.text = "Day " + level;
    48.         levelImage.SetActive (true);
    49.         Invoke("HideLevelImage", levelStartDelay);
    50.  
    51.         enemies.Clear ();
    52.         boardScript.SetupScene (level);
    53.     }
    54.  
    55.     private void HideLevelImage()
    56.     {
    57.         levelImage.SetActive (false);
    58.         doingSetup = false;
    59.     }
    60.  
    61.     public void GameOver()
    62.     {
    63.         Debug.Log("Attempting to show ending");
    64.         levelText.text = "After " + level + " days, you starved.";
    65.         levelImage.SetActive(true);
    66.         enabled = false;
    67.     }
    68.  
    69.     // Update is called once per frame
    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.  
    92.         for (int i = 0;i < enemies.Count;i++)
    93.         {
    94.             enemies[i].MoveEnemy();
    95.             yield return new WaitForSeconds(enemies[i].moveTime);
    96.         }
    97.         playersTurn = true;
    98.         enemiesMoving = false;
    99.     }
    100. }
    101.  
     
    Last edited: Sep 20, 2015
  5. TaikeiNoYuurei

    TaikeiNoYuurei

    Joined:
    Sep 20, 2015
    Posts:
    3
    I'm also having a problem with my animations not switching right away. Seems they're waiting for the end of the idle animation before switching over. I turned off the 'has exit time' as instructed, and otherwise they look identical. This is once again present in the complete version provided in the game assets, though I can clearly see it isn't the case on the video. I'm honestly not sure what information to provide, since I'm simply using the completed version to the same effect. I'm using unity 5.2

    Edit: This seems to have magically fixed itself after I restarted unity.
     
    Last edited: Sep 20, 2015
  6. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    I notice an error in the console showing a null reference exception for the Sound Manager, make sure that prefab is assigned in the loader script and also that the game manager is assigned there too. Check the Main scene in the Completed folder to compare.
     
  7. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    I'm not sure why the delay isn't working, I'll have to look at it myself and I actually haven't tested the project in 5.2 yet. We did have a similar issue with overlapping during the design phase of the project but the delay was preventing it to the best of my knowledge. If the delay is not working then it makes sense that they'd be getting stuck in the same space. WHY the delay isn't working is a bit of a mystery to me at this point. You could try replacing the line where you get the movetime from the enemy with a fixed move time or with turndelay, it may be some issue with getting the time from the list of enemies.
     
  8. Staize

    Staize

    Joined:
    Sep 30, 2015
    Posts:
    2
    Hey Matt I was working through the tut and I ran into an issue making the UI in Unity 5.2. Whenever I place the FoodText higher in the hierarchy so that it renders underneath the LevelImage layer the image messes up and the black screen goes away. I have no idea why this is happening or how to fix the issue. Thoughts?

     
    Last edited: Sep 30, 2015
  9. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    hey,

    I just reproduced the issue on my end, seems to be a (strange) bug. What precise version of Unity are you on? (under Help > About Unity) I reproduced on 5.21p1 which is latest.

    I've reported to the devs, I'll reply here when I learn more.
     
    Staize likes this.
  10. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    So it turns out this is a known bug in 5.21, the fix will be in a patch soon but for now please just assign either a black sprite or another solid sprite to the 'Source Image' field. I used the 'UISprite' in my demo project and it seemed to work fine. The issue is with having the Source Image set to 'None'. Thanks for the heads up!
     
    Staize likes this.
  11. Staize

    Staize

    Joined:
    Sep 30, 2015
    Posts:
    2
    I am on version 5.2.1f1

    No problem, thanks for looking into the issue for me. I have implemented the temperary fix and I should bust out the last 2 videos soon. Thanks again.
     
    Matthew-Schell likes this.
  12. sauder

    sauder

    Joined:
    Oct 1, 2015
    Posts:
    1
    As a novice programmer I have a two questions that are killing me. 1) How can I tweak the C# code to display a title screen with a "Start Button" when the game starts and 2)When it's game over, how can I return a player to the title screen? I'm riffing off of this project and trying to show this to my friends, but the way it stands now the game will auto start at Day 1 and end when you starve. Not the best player experience.

    I've created a canvas object (much like the Day 1 screen), created a private object in the GameManager script and referenced it in Awake(), but I don't know how to properly hide / destroy the object so it appears every time a Day X transition screen appears and does #2 above. Tweaking the Awake function could be the totally wrong approach. Any help here MUCH appreciated! Thanks.
     
  13. JaxD

    JaxD

    Joined:
    Sep 18, 2015
    Posts:
    7
    Hi,

    Im working on to expand this using the game project as a the base game. I am in 3rd year Computing course and have sufficient experience in C#. This is my list of plans to expand the game. I would value some advice and pointers, I'm not asking for full code help. Thanks for checking it out.


    1. Health system, zombies deal health damage. Health incrementally increases by each step(how?). Work from the how food register damage and replace it.

    2. Food system will work as stamina.

    3. Fuel collectible. Add collectible item, exit check item int before function

    4. Enemy variant with different behaviour. Create different enemy classes. Type 1, more damage. Type 2, moves every turn. Type 3, poison effect. Type 4, blind effect(create a black spotlight layer in the foreground that follows a player for certain amount of turns a la pokemon cave effect).

    5. Melee weapon that damages enemies considerable more, limited use.

    6. Gun weapon. OnClick to trigger damage.

    7. Finally, hardest, apply a level generation algorithm. Ive seen sample algorithms around best one I understand the most is from RogueBasin.

    http://www.roguebasin.com/index.php?title=Dungeon-Building_Algorithm


    EDIT: I just saw there's an upcoming tutorial on level generation. Made my day, can't wait.
     
    Last edited: Oct 2, 2015
  14. sexual_loogie

    sexual_loogie

    Joined:
    Jul 28, 2015
    Posts:
    2
    @Matthew Schell Great tutorial! Really got me started on unity and enjoying what I've done. I've had one issue that I can't seem to understand. The music added to the sound manager doesn't restart every level, but it adds a new instance of the music every level (overlapping the last). I can't really figure out where this is happening. any help would be appreciated!
     
  15. boxer997

    boxer997

    Joined:
    Feb 14, 2014
    Posts:
    2
    Hey, I wanted to say the tutorial is great. I had a lot of fun going through it. There are a few things I am looking to add that are outside the scope of the tutorial but I was wondering if I could get some help with allowing the player to attack enemies. I wrote some code that I feel should be working, but it is not.

    I modified the player script like this:
    Code (csharp):
    1.  
    2.         protected override void OnCantMove <T> (T component)
    3.         {
    4.  
    5.             if (component is Wall)
    6.             {
    7.                 //Set hitWall to equal the component passed in as a parameter.
    8.                 Wall hitWall = component as Wall;
    9.  
    10.                 //Call the DamageWall function of the Wall we are hitting.
    11.                 hitWall.DamageWall(playerDamage);
    12.  
    13.                 //Set the attack trigger of the player's animation controller in order to play the player's attack animation.
    14.                 animator.SetTrigger("playerChop");
    15.             }
    16.             else
    17.             {
    18.                 //Set hitEnemy to equal the component passed in as a parameter.
    19.                 Enemy hitEnemy = component as Enemy;
    20.  
    21.                 //Call the DamageEnemy function of the enemy we are hitting.
    22.                 hitEnemy.DamageEnemy(playerDamage);
    23.  
    24.                 //Set the attack trigger of the player's animation controller in order to play the player's attack animation.
    25.                 animator.SetTrigger("playerChop");
    26.             }
    27.          
    28.         }
    29.  
    and also the enemy script:

    Code (csharp):
    1.  
    2.         //DamageEnemy is called when the player attacks an enemy.
    3.         public void DamageEnemy(int loss)
    4.         {
    5.             //Call the RandomizeSfx function of SoundManager to play one of two chop sounds.
    6.             SoundManager.instance.RandomizeSfx(chopSound1, chopSound2);
    7.  
    8.  
    9.             //Subtract loss from hit point total.
    10.             enemyHealth -= loss;
    11.  
    12.             //If hit points are less than or equal to zero:
    13.             if (enemyHealth <= 0)
    14.                 //Disable the gameObject.
    15.                 gameObject.SetActive(false);
    16.         }
    17.  
    These changes seem to amount to nothing. I still destroy walls, and still cannot attack enemies. Any help anyone can give would be greatly appreciated.
     
  16. JaxD

    JaxD

    Joined:
    Sep 18, 2015
    Posts:
    7
    Hi, I am actually working on the same issue as yourself. I found that you might be missing this.


    Code (CSharp):
    1. if (horizontal != 0 || vertical != 0)
    2.         {
    3.             AttemptMove<Wall>(horizontal, vertical);
    4.             AttemptMove<Enemy>(horizontal, vertical);//This line
    5.         }
    There is a bigger issue at hand. It's that if you deactivate the enemy after it dies, it will still register damage to the player when it is where it "died". I used Destroy gameobject but prevents the player from moving afterwards. Either way it seem to affecting the "turns" co-routine. So I'm still trying to figure that part out.

    I would prefer to use destroy to remove the enemy from the hierarchy. The issue seems to lay in the MoveEnemies coroutine.

    EDIT:
    I solved it man! So sticking with destroying the enemy gameobject. They enemies are added in the enemies array list and turns are resolved on if there are enemies or not. So i added a function in GameManager script that removes an enemy from an array and calling that function when an enemy is dies. I've tested fighting more than one enemy to see if it might delete the entire list and disable the movement of other enemies and I'm glad to say it doesn't. It works just fine.

    GameManager script
    Code (CSharp):
    1. public void AddEnemyToList(Enemy script)//enemies register themselves to gamemanager
    2.     {
    3.         enemies.Add(script);
    4.     }
    5.  
    6.     public void RemoveEnemyFromList(Enemy script)
    7.     {
    8.         enemies.Remove(script);
    9.     }
    Enemy script
    Code (CSharp):
    1. if (enemeyHealthPoints <= 0)
    2.         {
    3.             Destroy(gameObject);
    4.             GameManager.instance.RemoveEnemyFromList(this);
    5.         }
     
    Last edited: Oct 3, 2015
  17. boxer997

    boxer997

    Joined:
    Feb 14, 2014
    Posts:
    2
    Hey, thanks for the reply. I actually, eventually, figured out a way to fix it. I made AttemptMove a bool, so that I could get a return value telling me whether or not something was hit because I realized I needed to add this AttemptMove<Enemy>(horizontal, vertical) exactly where you show, but I didn't really know how to figure out, within the game, when I needed that check. Any way eventually I got this,

    Code (csharp):
    1.  
    2.         protected override bool AttemptMove <T> (int xDir, int yDir)
    3.         {
    4.          
    5.             //Update health text display to reflect current score.
    6.             healthText.text = "Health: " + health;
    7.          
    8.             //Call the AttemptMove method of the base class, passing in the component T (in this case Wall) and x and y direction to move.
    9.             bool b = base.AttemptMove <T> (xDir, yDir);
    10.          
    11.             //Hit allows us to reference the result of the Linecast done in Move.
    12.             RaycastHit2D hit;
    13.  
    14.             //If Move returns true, meaning Player was able to move into an empty space.
    15.             if (Move(xDir, yDir, out hit))
    16.             {
    17.                 //Call RandomizeSfx of SoundManager to play the move sound, passing in two audio clips to choose from.
    18.                 SoundManager.instance.RandomizeSfx (moveSound1, moveSound2);
    19.             }
    20.          
    21.             //Since the player has moved and lost health points, check if the game has ended.
    22.             CheckIfGameOver ();
    23.          
    24.             //Set the playersTurn boolean of GameManager to false now that players turn is over.
    25.             GameManager.instance.playersTurn = false;
    26.  
    27.             return b;
    28.         }
    29.  
    and then this,

    Code (csharp):
    1.  
    2. if(horizontal != 0 || vertical != 0)
    3.             {
    4.                 //Call AttemptMove passing in the generic parameter Wall, since that is what Player may interact with if they encounter one (by attacking it)
    5.                 //Pass in horizontal and vertical as parameters to specify the direction to move Player in.
    6.                 bool b = AttemptMove<Wall> (horizontal, vertical);
    7.                 if (!b) AttemptMove<Enemy>(horizontal, vertical);
    8.  
    9.             }
    10.  
    And it worked - sort of. I realized it only seemed to be deleting enemy sprites, based on this, which I posed earlier

    Code (csharp):
    1.  
    2.  
    3.  //If hit points are less than or equal to zero:
    4.            if (enemyHealth <= 0)
    5. //Disable the gameObject.
    6.                gameObject.SetActive(false);
    7.  
    8.  
    I guess it wasn't ending the script which was still trying to deal damage to me.

    So then I logged on here this morning and saw your post (JaxD) and read what you posted about creating a RemoveEnemyFromList function and realized that was exactly what I needed. So you probably saved me many hours, thanks.
     
    Matthew-Schell and JaxD like this.
  18. JaxD

    JaxD

    Joined:
    Sep 18, 2015
    Posts:
    7
    Yeah my AttemptMove<Enemy> seems to be just not how its suppose to be. I see you use bool. But what if theres more types? I was going to add enemy types. How would you adjust AttemptMove<> for that?


    I highly suggest to destroy each enemy object than deactivating them. They will remain in the hierarchy and just take up unnecessary resources.
     
    Last edited: Oct 4, 2015
  19. JaxD

    JaxD

    Joined:
    Sep 18, 2015
    Posts:
    7
    I created a main menu system. Taking advice from the previous posts in this forum, I had bool "restart" in my GameManager to allow the game to start at day 1 with my Menu scene.

    Now I'm having an issue with going back to the Menu from the Game scene. The GameManager will persist, as it should, but it breaks my Menu. So I had my "Back to Menu" button destroy the GameManager before switching to the "Menu" scene, it didnt work.

    I created a line in Awake of GameManager.

    Code (CSharp):
    1.  
    2.         if (Application.loadedLevelName.Equals("Menu"))
    3.             Destroy(gameObject);
    4.         else
    5.         DontDestroyOnLoad(gameObject);
    Still hangs my "Menu" scene with an error
     
  20. Ziggy26

    Ziggy26

    Joined:
    Jul 26, 2015
    Posts:
    1
    Hello yesterday I've started the tutorial and got until video 11 Enemy Animator Controller where I got stuck. I've followed the tutorial step by step and after correcting some of my typing errors I still remained with 2 errors in GameManager script that appear in Unity console tab. Both errors are saying the same thing, but on different lines,
    . So I've checked the code a couple of times, re-write it and even copy-paste the code beneath the video, to be absolutely sure that is not a typing error or something that I miss, but still the same errors persist.
    After trying to continue with the tutorial and add the Enemy script to the enemies prefabs I've noticed that the script doesn't appear in Component > Scripts.

    L.E.
    So I had solved the issue the long way, but now I'm having problems moving the player. It moves only once and but the food still lowers after each press of a button.
     
    Last edited: Oct 6, 2015
  21. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    Good morning Roguelike fans!

    I've just posted an archive of the live training session Monday on Basic 2D Dungeon Generation which uses the 2DRL assets completed project as a starting point.

    PLEASE NOTE: This is not a direct extension of this project. Some of what I did in the training breaks the project and you will need to do some work and figure out how to integrate the two if you want to take it further.

    http://unity3d.com/learn/tutorials/modules/intermedia/live-training-archive/2d-dungeon-generation

    A request: If anyone does the work to integrate these changes into the main project, paste your code or the steps that you took to do so. I have a huge backlog of other content I need to make for the Unity Learn site so won't be able to do it any time soon.

    A couple things you will need to do for sure:

    1) Re-establish the reference to the Food text since the player is now being instantiated instead of originating in the scene already.

    2) Find a creative way to spawn enemies and pickups inside rooms. I recommend piggy backing off the room generation code, maybe adding a SpawnEnemies and SpawnItems to BoardCreator which uses the locations in the rooms[] array to make sure they are in bounds.

    3) Do something similar to place the exit, maybe in the last room in the rooms array so that it's far from player at start?

    4) Have GameManager call BoardCreator instead of BoardManager to generate the level.

    5) More things I can't think of.

    If you make something that uses any of this send me a link! I love these kind of games and would love to see what you do.
     
    Deleted User likes this.
  22. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    There are some people who addressed this earlier in the thread, take a read backward. I'm here to answer questions pertaining to the tutorial content, if you want to extend, you'll need to figure it out.
     
  23. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238

    For 7, check out the archive I just posted. I think for many of the things you want to do it can be done relatively easily with the existing code base, good luck!
     
  24. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    It's possible that you've saved the SoundManager in the hierarchy and are adding another copy whenever you reload the scene. Neither the GameManager or SoundManager prefabs should be in hierarchy. Compare your scene to the scene in the Completed > Scenes folder.
     
  25. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    FYI deactivating is fine, they won't take up CPU/GPU resources and will be destroyed when re-loading the level.
     
  26. Buscemi

    Buscemi

    Joined:
    Oct 21, 2014
    Posts:
    8
    Hi!
    I'm having a big problem. I've followed the tutorial, made the prefabs and attached the scipts in the exact way it's done in the videos. But my player won't appear in the game! When I play the scene, the ground-, wall-, outer wall tiles and enemies all appear just as they're supposed to, but the player just doesn't...

    Even when I manually place the player prefab in the scene, I can only move once, then everything stops, and I can move through everything in the BlockingLayer. Any idea what's worng?
     
  27. fepayton

    fepayton

    Joined:
    Oct 9, 2015
    Posts:
    1
    I got this error in both this project and in the ZomBunny Survival Shooter. It happens when: an image without a Source image or a material is listed on a Canvas below another object that has a Source image or text. Either setting the image (like you said) or setting the material (I used Sprite-default) resolves the issue.
    Hope this helps.

    Running Unity 5.2.1f1
     
    Matthew-Schell likes this.
  28. Transire

    Transire

    Joined:
    Oct 3, 2015
    Posts:
    1
    SOLVED!!!!

    hey i have a problem with the outer wall tiles, everything can be seen in the game view but the outer wall tiles dont show, the exit tile does and its where it should be, i have tried using the complete script just to check but i still cant see the outer walls.. please help im a beginner so i hope this doesnt seem to idiotic of me.thanks :) hope i can use screenshots on here please let me know if im not supposed to? this is what i can see in game view.. upload_2015-10-11_11-28-44.png

    okay so i after an hour or two of pure re capping i discovered that i was being lazy and copying and pasting my scripts... i type them all myself this once i cheated and learned the hard way... dont copy and paste!! Chuffed i worked it out!!1 :D thanks anyways!
     

    Attached Files:

    Last edited: Oct 11, 2015
    Matthew-Schell and Mohobie like this.
  29. Nenhoz

    Nenhoz

    Joined:
    Sep 13, 2015
    Posts:
    1
    I managed to fix this issue by changing FoodText material from None to Font Material.
     
    Matthew-Schell likes this.
  30. Oscaruzzo

    Oscaruzzo

    Joined:
    Jan 26, 2015
    Posts:
    17
    Really nice tutorial.

    BTW for some reason, whoever wrote the transcripts and the closed captions used consistently the word "parse" instead of "pass" and "parsing" instead of "passing" like in «we call AttemptMove parsing in our xDir and our yDir» instead of "passing in our xDir and our yDir". Just letting you know, that looks strange :p
     
    Matthew-Schell likes this.
  31. Oscaruzzo

    Oscaruzzo

    Joined:
    Jan 26, 2015
    Posts:
    17
    Just a minor issue in this tutorial. In video 12 you say at 8:38

    This is actually not true. The player can move while the black screen is shown (try it!), because playersTurn is true. Adding a check for doingSetup just prevents enemies from moving, but this a redundant check, also because playersTurn is true.

    I guess you have to check in Player.Update() for doingSetup, so in Player.cs

    Code (CSharp):
    1. private void Update () {
    2.     //If it's not the player's turn, exit the function.
    3.     if(!GameManager.instance.playersTurn) return;
    4. ...
    would become

    Code (CSharp):
    1. private void Update () {
    2.     //If it's not the player's turn, exit the function.
    3.     if(!GameManager.instance.playersTurn || GameManager.instance.doingSetup)
    4.         return;
    5. ...
    Also the doingSetup field has to become public.
     
    Last edited: Oct 12, 2015
    JaxD likes this.
  32. Sandbird_

    Sandbird_

    Joined:
    Oct 19, 2015
    Posts:
    3
    I am having a small problem, and i dont know if its Unity's fault or something from the source files.
    I wanted to make an info sign, so when the player ends up on that tile, it will show a random text on screen.
    So i created a sign sprite, with an onTrigger collider on it and tagged it 'Sign'.
    Problem is that instead of showing the message only when OnTriggerEnter2D is fired up, it also shows it when the player exits that tile....although there is nothing in OnTriggerExit2D. Is this a unity bug ?
    I even made the sign collider a bit smaller so its not exactly the same size as the player...because the edges would touch when the 2 sprites were side by side.

    player.cs
    Code (CSharp):
    1.  
    2. public Text signText;
    3. public GameObject signObj;
    4. public IntRange numTip = new IntRange (0, 3);
    5. private static string[] TIPS = {"msg1", "msg2", "msg3"};
    6. // ......
    7. private void OnTriggerEnter2D (Collider2D other)
    8. {
    9. // ......
    10.    else if(other.tag == "Sign")
    11.    {
    12.      int tL = numTip.Random;
    13.      if (tL < TIPS.Length) {
    14.        signObj = GameObject.Find("SignText");
    15.        signText = signObj.GetComponent<Text> ();
    16.        signText.text = TIPS[tL];  // Show the random msg on the text field
    17.      }
    18.    }
    19. }
     
    Last edited: Oct 20, 2015
  33. rafsha92

    rafsha92

    Joined:
    Oct 21, 2015
    Posts:
    1
    Excuse me.. i follow all the steps in the video until part 11 .. but, i still don't know why i cant move the player using keyboard button.. can you help me with this? and also there is also an error in my player script, NullReferenceException: object reference not set to an instance of an object
     
  34. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    The Player should be in the hierarchy before you start the scene. Drag him in and save him in your scene. If he can move through walls, make sure he's set to BlockingLayer as well and that he has a BoxCollider2D that is not set to trigger attached.
     
  35. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    You're correct, pretty sure this is fixed in 5.21p4, I raised it with UI guys and they said the fix was going out in p3.

    Patches here:
    https://unity3d.com/unity/qa/patch-releases
     
  36. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    Not completely sure about this one and haven't tested since it's not part of the original tutorial BUT, I'd just add a boolean to check if the sign is showing and turn it on and off as needed.
     
    Sandbird_ likes this.
  37. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    Shoot you're right! Funnily enough no one has noticed so far :) I'll chalk that one up to a learning experience for the people who want to extend this further.
     
    Oscaruzzo likes this.
  38. 8bitcarrot

    8bitcarrot

    Joined:
    Oct 21, 2015
    Posts:
    1
    Getting this error:

    Assets/Scripts/Enemy.cs(19,46): error CS1061: Type `Completed.GameManager' does not contain a definition for `AddEnemyToList' and no extension method `AddEnemyToList' of type `Completed.GameManager' could be found (are you missing a using directive or an assembly reference?)

    Did I miss something in the GameManager script? (I am on video 11)
     
  39. fruitdealer

    fruitdealer

    Joined:
    Oct 25, 2015
    Posts:
    2
    I'm having trouble understanding the script used in video 4 (Writing the board manager):

    Why are boardHolder and gridPosition made using the private access modifier? What are the possible reasons for using private besides making things invisible to the inspector? Also I don't quite understand the return type void. MSDN says that: "When used as the return type for a method, void specifies that the method doesn't return a value." The InitialiseList -function returns us a list of vector3 values corresponding to all points on the game board. How is this different from returning a numeric value?

    These questions most likely make no sense whatsoever :)
     
  40. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    It's a bit hard to tell from what you've posted. Can you post your code? Use code tags for formatting, see top of thread for how to do it. One thing that may be an issue is if you are mixing scripts from the Completed namespace (this may happen if you're using scripts from the completed folder or pasted from the site).
     
  41. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    238
    boardHolder and gridPosition are private since they don't need to be accessed by other scripts, to avoid cluttering the inspector and since it's generally good practice to keep things private that don't need to be public. The return type void means that that method has a return type void, it doesn't return a value. These are methods that we are not using to calculate something for another function, therefore they don't need to return anything.

    InitializeList in BoardManager also has a return type of void so it doesn't actually return anything. It does add positions to our list gridpositions but this is different from returning a value. It might be a good idea to review the heading "Return Values" on this page to bone up on the concept.

    https://msdn.microsoft.com/en-us/library/ms173114.aspx
     
  42. fruitdealer

    fruitdealer

    Joined:
    Oct 25, 2015
    Posts:
    2
    Thanks for the answer. I've ran into an actual problem though. I've done 9 out of 14 parts of the tutorial and my player can only move once. I've triple checked the code and my player is on blockinglayer and the transform is at (0, 0, 0). Is the player supposed to be able to move freely at this point in the tutorial?

    Edit: Ok so I followed the tutorial a little bit further and started to get compilation errors and couldn't figure out why. Then I figured what if I just use the scripts from the the completed folder.

    I managed to make the game compile but now my player is unable to move at all and the board is completely black. I think I'm gonna try some other tutorials instead.
     
    Last edited: Oct 26, 2015
  43. Fragmental

    Fragmental

    Joined:
    Jun 30, 2013
    Posts:
    61
    I'm having issues with character movement. In the editor, the characters will mostly move fine, but when I build, all of the characters move, VERY slowly. It takes roughly two full seconds for a character to move into position. Everything else seems to run at full speed, but the cpu usage in the build is much higher than in the editor.

    Also, even in the editor, there are still sometimes issues with the player character kind of weaving around and not staying square on a tile, so that if you walk by food it will pick up food on both tiles, etc.

    Any ideas about what might be causing this?

    edit:
    here's an example of the slow movement in the build. The character also doesn't seem to always stay within the bounds of the tiles and weaves just as it did in the editor, only much slower.

    and here's an example of the the weaving the player does in the editor.

    The character also glides from position to position without stop when holding the button down. And when checking the completed project today, the character seems to stop briefly before going on to the next tile when the button is held down. This behavior seems somewhat random, because even with nothing changed, the player will sometimes move normally.

    Another Edit:
    Here is a link to download the debug build

    Yet Another Edit:
    I finally resolved this today by exporting all of my assets, with dependencies to a unitypackage. Then I created a new project and imported the package. I then closed unity(not sure closing was necessary just did it anyway) and copied the tagmanager.asset folder from the project settings of the original project to the new project. I then opened unity back up, updated the build settings in the new project, and built the project and everything seems to be working perfectly. At first there was a few issues with lines across the game board but it seemed to resolve itself when I updated the build settings.

    I think there was something wrong with the project itself. I've had multiple odd issues that clued me in to an issue with the project. I don't know if it happened during a unity upgrade or a crash of unity or when the computer crashed or during a hard shutdown or what. I just know that it's working now.
     
    Last edited: Nov 12, 2015
  44. C4G65

    C4G65

    Joined:
    Nov 3, 2015
    Posts:
    4
    Why are using vector3 in 2d game? Isnt it too heavy for 2d game purposes aswell?
     
    Last edited: Nov 3, 2015
  45. mrianmerry

    mrianmerry

    Joined:
    Nov 6, 2015
    Posts:
    3
    Hmmm. I've run into an issue with Part 9 of this tutorial.

    Code (CSharp):
    1. protected override void AttemptMove<T>(int xDir, int yDir)
    2.     {
    3.         _food--;
    4.  
    5.         base.AttemptMove<T>(xDir, yDir);
    6.  
    7.         RaycastHit2D hit;
    8.         CheckIfGameOver();
    9.         GameManager.instance.PlayerTurn = false;
    10.     }
    I'm getting an error on the callback to the parent AttemptMove that says:
    The type 'T' cannot be used as type parameter 'T' in the generic type or method 'MovingObject.AttemptMove<T>(int, int)'. There is no boxing conversion or type parameter conversion from 'T' to 'UnityEngine.Component'.

    The MovingObject function is as follows:
    Code (CSharp):
    1. protected void AttemptMove <T> (int xDir, int yDir) where T : Component
    2.     {
    3.         RaycastHit2D hit;
    4.         bool canMove = Move(xDir, yDir, out hit);
    5.  
    6.         if (hit.transform == null)
    7.             return;
    8.  
    9.         T hitComponent = hit.transform.GetComponent<T>();
    10.  
    11.         if (!canMove && hitComponent != null)
    12.             OnCantMove(hitComponent);
    13.     }
    However, this is the exact code that was typed in up to this point in the tutorial, so I'm really not sure how to go about solving this.

    I attempted to add where T : Component to the end of the function override declaration, but that threw up a different error:
    Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly


    EDIT:

    A little more digging after sleep turned up the problem with my code.
    I'd managed (as you can see above) to not include the virtual keyword in the MovingObject AttemptMove declaration. Having put it in as intended, the Player AttemptMove as above works fine.

    ...Amazing, the little things you overlook.
     
    Last edited: Nov 7, 2015
    Matthew-Schell likes this.
  46. mephis2412

    mephis2412

    Joined:
    Feb 28, 2015
    Posts:
    1
    I have a problem when moving the Player. If I press a movement key once at a time, it works perfect. But if I hold down the key, the Player is starting get float value for Axis. Even though I followed the script tutorial and converted Input value to Integer.
    And the Player is still able to trigger OnCantMove with Walls and destroy it but if the collider is Enemy, it just ignore and move through as if there is nothing; it makes both player and enemy are in a same square sometimes.
    Do you have any idea where the problem could be? Thanks.
     
  47. twilightZone

    twilightZone

    Joined:
    Oct 10, 2014
    Posts:
    30
    Hello all,

    I do not know, if I can ask this question, but I do not understand

    Code (CSharp):
    1. namespace Completed
    And I can not find the answer in the documentation

    Thanks a lot
    Patrick
     
  48. Fragmental

    Fragmental

    Joined:
    Jun 30, 2013
    Posts:
    61
    @twilightZone

    Here's a couple links on Namespaces in C#
    https://msdn.microsoft.com/en-us/library/dfb3cx8s.aspx
    https://msdn.microsoft.com/en-us/library/z2kcy19k.aspx
    https://msdn.microsoft.com/en-us/library/0d941h9d.aspx

    In this case, Matthew is using the "Completed" namespace to keep the scripts separate from the scripts that we create, so that they won't conflict with each other. Without that namespace declaration, when we create the new scripts during the tutorial that are essentially copies of the current scripts, that would create errors in the console. I believe the scripts in the same namespace can interact with each other. A script in a different namespace can also interact with a different namespace with a line like "using Completed;".
     
    Matthew-Schell likes this.
  49. twilightZone

    twilightZone

    Joined:
    Oct 10, 2014
    Posts:
    30
  50. Alpha37

    Alpha37

    Joined:
    Nov 14, 2015
    Posts:
    1
    Hi,
    I am a beginner on Unity andI have a problem with the end of a level (I'm on the step 11) of the tutorial. At each end of a level the gameManager create a new boardScript but cannot destroy the previous. I don't know why... I have found a solution but I think it's a bad solution :

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class GameManager : MonoBehaviour {
    6.  
    7.     public float turnDelay = .1f;
    8.     public static GameManager instance = null;
    9.     private BoardManager boardScript;
    10.     public int playerFoodPoints = 100;
    11.     [HideInInspector] public bool playersTurn = true;
    12.  
    13.     private int level = 1;
    14.     private List<Ennemy> enemies;
    15.     private bool enemiesMoving;
    16.  
    17.     // Use this for initialization
    18.     void Awake () {
    19.         if (instance == null)
    20.             instance = this;
    21.         else if (instance != this)
    22.             Destroy (gameObject);
    23.         DontDestroyOnLoad (gameObject);
    24.         boardScript = GetComponent<BoardManager>();
    25.         enemies = new List<Ennemy> ();
    26.         InitGame ();
    27.     }
    28.  
    29.     void InitGame(){
    30.         enemies.Clear ();
    31.         boardScript.SetupScene (level);
    32.     }
    33.  
    34.     //This is called each time a scene is loaded.
    35.     void OnLevelWasLoaded(int index)
    36.     {
    37.         //Add one to our level number.
    38.         if (level != 1) {
    39.             Destroy (GetComponent<BoardManager> ());
    40.         }
    41.  
    42.         level++;
    43.         //Call InitGame to initialize our level.
    44.         InitGame();
    45.     }
    46.  
    47.     public void GameOver(){
    48.         enabled = true;
    49.     }
    50.     // Update is called once per frame
    51.     void Update () {
    52.         if (playersTurn || enemiesMoving)
    53.             return;
    54.         StartCoroutine (MoveEnnemies ());
    55.     }
    56.  
    57.     public void AddToList(Ennemy script){
    58.         enemies.Add (script);
    59.     }
    60.  
    61.     IEnumerator MoveEnnemies(){
    62.         enemiesMoving = true;
    63.         yield return new WaitForSeconds (turnDelay);
    64.         if (enemies.Count == 0) {
    65.             yield return new WaitForSeconds(turnDelay);
    66.         }
    67.  
    68.         for (int i = 0; i < enemies.Count; i++)
    69.         {
    70.             //Call the MoveEnemy function of Enemy at index i in the enemies List.
    71.             enemies[i].MoveEnnemy ();
    72.            
    73.             //Wait for Enemy's moveTime before moving next Enemy,
    74.             yield return new WaitForSeconds(enemies[i].time);
    75.         }
    76.  
    77.         playersTurn = true;
    78.         enemiesMoving = false;
    79.         }
    80.  
    81. }
    My question is to know that is the best way to do that and what step of the tutorial I forgot.
    Thanks in advance :)
     
Thread Status:
Not open for further replies.