Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    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. deviantony

    deviantony

    Joined:
    Feb 27, 2013
    Posts:
    6
    Yeah, fixes the OnLevelWasLoaded issue ! Thanks spg !

    @eljeffe418 Have a look at this fix, it will solve your problem.

    Also, about the screen size issue, this topic helped me to solve my problem: http://answers.unity3d.com/questions/464487/windowed-game-to-fullscreen.html

    Have fun :)
     
  2. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    hey all just a quick update about the bug with OnLevelWasLoaded. I've heard back from the devs, they've isolated the issue and we should see a fix in 5.4. Thanks!
     
    tarod-net likes this.
  3. WaterMonkey79

    WaterMonkey79

    Joined:
    Jan 15, 2016
    Posts:
    9
    Did anyone figure out a fix for the build
     
  4. WaterMonkey79

    WaterMonkey79

    Joined:
    Jan 15, 2016
    Posts:
    9
    I am having trouble with building for Android. Every thing works great in Unity 5 but when i build i get a compiling error that says that the Application.LoadLeve(Application.LoadLevel) is obsolete that it needs to be SceneManager.LoadScene can you please help me to figure this out. I havent changed much and I have a really good game concept but i cant get this to build correctly. When i load game after building it for standalone it also starts at Day 2 and the jumps to day 4 then i die. NO FOOD. so would you please explain this for me please? or possibly update the code?

    Also cannot restart after player dies?
    Please help asap

    I am ready to build soon as i can fix this. Thank you and hope to hear from you soon!
    Compiling error

    //Restart reloads the scene when called.
    private void Restart()
    {
    Application.LoadLevel(Application.loadedLevel);

    }
     
  5. WaterMonkey79

    WaterMonkey79

    Joined:
    Jan 15, 2016
    Posts:
    9
    I put this in for the scene manager but it says that there is no content SceneMangaer . how to i do this so i can build for android?

    this is what i put inplace of Application.LoadLevel(Application.loadedLevel);

    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

    how do i fix this?
    i get a compiling error every time i copy and paste it in
     
  6. WaterMonkey79

    WaterMonkey79

    Joined:
    Jan 15, 2016
    Posts:
    9
    UPDATE build the game in Unity 5.2 and the games works great!!!

    game does not restart

    The problem i am having now is I am not sure how to put the restart button in. But everything i have tried doesn't seen to work. Could someone show me how it should look in the code. I am new to this and really learn better if i can see it. cause its like a big mess in my head right now lol. Any help would be appreciated.
     
  7. WaterMonkey79

    WaterMonkey79

    Joined:
    Jan 15, 2016
    Posts:
    9
    a quit game button would be awesome too if possible
     
  8. BlackBat023

    BlackBat023

    Joined:
    Feb 9, 2016
    Posts:
    14
    Hi all. I am very new to game development and C# coding. I do have, however, experience in Python and some other languages. I have followed the 2DRogueLike tutorial up to point 4.2 and upon testing the game I encountered the following 5 errors:

    1.
    NullReferenceException: Object reference not set to an instance of an object
    Player.AttemptMove[Wall] (Int32 xDir, Int32 yDir) (at Assets/Scripts/Player.cs:68)
    Player.Update () (at Assets/Scripts/Player.cs:55)

    2.
    NullReferenceException: Object reference not set to an instance of an object
    Player.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/Player.cs:94)

    3.
    NullReferenceException: Object reference not set to an instance of an object
    Wall.DamageWall (Int32 loss) (at Assets/Scripts/Wall.cs:21)
    Player.OnCantMove[Wall] (.Wall Component) (at Assets/Scripts/Player.cs:102)
    MovingObject.AttemptMove[Wall] (Int32 xDir, Int32 yDir) (at Assets/Scripts/MovingObject.cs:66)
    Player.AttemptMove[Wall] (Int32 xDir, Int32 yDir) (at Assets/Scripts/Player.cs:63)
    Player.Update () (at Assets/Scripts/Player.cs:55)

    4.
    NullReferenceException: Object reference not set to an instance of an object
    Player.AttemptMove[Wall] (Int32 xDir, Int32 yDir) (at Assets/Scripts/Player.cs:68)
    Player.Update () (at Assets/Scripts/Player.cs:55)

    5.
    NullReferenceException: Object reference not set to an instance of an object
    Enemy.OnCantMove[Player] (.Player component) (at Assets/Scripts/Enemy.cs:58)
    MovingObject.AttemptMove[Player] (Int32 xDir, Int32 yDir) (at Assets/Scripts/MovingObject.cs:66)
    Enemy.AttemptMove[Player] (Int32 xDir, Int32 yDir) (at Assets/Scripts/Enemy.cs:32)
    Enemy.MoveEnemy () (at Assets/Scripts/Enemy.cs:47)
    GameManager+<MoveEnemies>c__Iterator3.MoveNext () (at Assets/Scripts/GameManager.cs:96)

    What happens when I fire up the game is that the Player moves more than one block sometimes. I also get no movement sounds. Upon colliding with either food or soda the gameObject does not get de-activated and stays active and no eatSound or drinkSound is played. Upon colliding with either enemy1 or enemy2 the player hit animation isn't activated, the enemyAttack1 or enemyAttack2 sound is not played. Also if the food counter reaches 0 the game does not terminate. It simply sends the food count into a - and carry on with the came.

    If anyone could help me out with some solutions I will be very grateful as I have now scrutinized the code with a fine tooth comb and I see no discrepancies between my code and the examples given.

    Thanks,
    BlackBat
     
  9. WaterMonkey79

    WaterMonkey79

    Joined:
    Jan 15, 2016
    Posts:
    9
    Did you delete the animator for the player? I know that when i did that once i had simular results replaced the animator and cleared
     
  10. WaterMonkey79

    WaterMonkey79

    Joined:
    Jan 15, 2016
    Posts:
    9
    would you show me how to properly put a restart button when game ends with the image Day 1 survived?
    I am very new and I am trying to put in something like Application.Restart or something but i don't know how to do it could you help me please?
     
  11. deviantony

    deviantony

    Joined:
    Feb 27, 2013
    Posts:
    6
  12. BlackBat023

    BlackBat023

    Joined:
    Feb 9, 2016
    Posts:
    14
    I checked and the Player animator is still there...
     
  13. TheOriginalMomos

    TheOriginalMomos

    Joined:
    Sep 5, 2013
    Posts:
    4
    Hello, hello!

    I'm having a problem! Everything works fine when I test the game until I try to go to day 2. Nothing loads and I get the Day 1 screen instead of Day 2.

    Any idea what could be causing the problem?
     
  14. WaterMonkey79

    WaterMonkey79

    Joined:
    Jan 15, 2016
    Posts:
    9
    I have been thru the space shooter tutorial i dont understand the difference between GameController and GameManager
    so i have been trying to set up a button like in the space shooter tutorial. I dont know much about coding and i am just gettting started but i have spent hours trying to slowly create this button. The button currently stays on scene the whole game and it changes colors. When clicked it does nothing here is how i have been trying to do this would someone please help?

    using UnityEngine;
    using System.Collections;

    namespace Completed
    {
    using System.Collections.Generic; //Allows us to use Lists.
    using UnityEngine.UI; //Allows us to use UI.

    public class GameMangager : MonoBehaviour
    {
    public float levelStartDelay = 2f; //Time to wait before starting level, in seconds.
    public float turnDelay = 0.1f; //Delay between each Player turn.
    public int playerFoodPoints = 100; //Starting value for Player food points.
    public static GameMangager instance = null; //Static instance of GameManager which allows it to be accessed by any other script.
    [HideInInspector] public bool playersTurn = true; //Boolean to check if it's players turn, hidden in inspector but public.


    private Text levelText; //Text to display current level number.
    private GameObject levelImage; //Image to block out level as levels are being set up, background for levelText.
    private BoardManager boardScript; //Store a reference to our BoardManager which will set up the level.
    private int level = 1; //Current level number, expressed in game as "Day 1".
    private List<Enemy> enemies; //List of all Enemy units, used to issue them move commands.
    private bool enemiesMoving; //Boolean to check if enemies are moving.
    private bool doingSetup = true; //Boolean to check if we're setting up board, prevent Player from moving during setup.
    public GameObject restartButton;


    //Awake is always called before any Start functions
    void Awake()
    {
    restartButton.SetActive(false);

    //Check if instance already exists
    if (instance == null)

    //if not, set instance to this
    instance = this;

    //If instance already exists and it's not this:
    else if (instance != this)

    //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
    Destroy(gameObject);

    //Sets this to not be destroyed when reloading scene
    DontDestroyOnLoad(gameObject);

    //Assign enemies to a new List of Enemy objects.
    enemies = new List<Enemy>();

    //Get a component reference to the attached BoardManager script
    boardScript = GetComponent<BoardManager>();

    //Call the InitGame function to initialize the first level
    InitGame();
    }

    //This is called each time a scene is loaded.
    void OnLevelWasLoaded(int index)
    {
    //Add one to our level number.
    level++;
    //Call InitGame to initialize our level.
    InitGame();
    }

    //Initializes the game for each level.
    void InitGame()
    {
    //While doingSetup is true the player can't move, prevent player from moving while title card is up.
    doingSetup = true;

    //Get a reference to our image LevelImage by finding it by name.
    levelImage = GameObject.Find("LevelImage");

    //Get a reference to our text LevelText's text component by finding it by name and calling GetComponent.
    levelText = GameObject.Find("LevelText").GetComponent<Text>();

    //Set the text of levelText to the string "Day" and append the current level number.
    levelText.text = "Night " + level;

    //Set levelImage to active blocking player's view of the game board during setup.
    levelImage.SetActive(true);

    //Call the HideLevelImage function with a delay in seconds of levelStartDelay.
    Invoke("HideLevelImage", levelStartDelay);

    //Clear any Enemy objects in our List to prepare for next level.
    enemies.Clear();

    //Call the SetupScene function of the BoardManager script, pass it current level number.
    boardScript.SetupScene(level);

    }


    //Hides black image used between levels
    void HideLevelImage()
    {
    //Disable the levelImage gameObject.
    levelImage.SetActive(false);

    //Set doingSetup to false allowing player to move again.
    doingSetup = false;
    }

    //Update is called every frame.
    void Update()
    {
    //Check that playersTurn or enemiesMoving or doingSetup are not currently true.
    if (playersTurn || enemiesMoving || doingSetup)

    //If any of these are true, return and do not start MoveEnemies.
    return;

    //Start moving enemies.
    StartCoroutine(MoveEnemies());
    }

    //Call this to add the passed in Enemy to the List of Enemy objects.
    public void AddEnemyToList(Enemy script)
    {
    //Add Enemy to List enemies.
    enemies.Add(script);
    }


    //GameOver is called when the player reaches 0 food points
    public void GameOver()
    {
    //Set levelText to display number of levels passed and game over message
    levelText.text = "After " + level + " days, you starved.";

    //Enable black background image gameObject.
    levelImage.SetActive(true);

    //Disable this GameManager.
    enabled = false;

    restartButton.SetActive(true);
    }


    //Coroutine to move enemies in sequence.
    IEnumerator MoveEnemies()
    {
    //While enemiesMoving is true player is unable to move.
    enemiesMoving = true;

    //Wait for turnDelay seconds, defaults to .1 (100 ms).
    yield return new WaitForSeconds(turnDelay);

    //If there are no enemies spawned (IE in first level):
    if (enemies.Count == 0)
    {
    //Wait for turnDelay seconds between moves, replaces delay caused by enemies moving when there are none.
    yield return new WaitForSeconds(turnDelay);
    }

    //Loop through List of Enemy objects.
    for (int i = 0; i < enemies.Count; i++)
    {
    //Call the MoveEnemy function of Enemy at index i in the enemies List.
    enemies.MoveEnemy ();

    //Wait for Enemy's moveTime before moving next Enemy,
    yield return new WaitForSeconds(enemies.moveTime);
    }
    //Once Enemies are done moving, set playersTurn to true so player can move.
    playersTurn = true;

    //Enemies are done moving, set enemiesMoving to false.
    enemiesMoving = false;
    }

    public class Completed.GameMangager.RestartGame();

    }
    }
     
  15. WaterMonkey79

    WaterMonkey79

    Joined:
    Jan 15, 2016
    Posts:
    9
    Game also will not load first level now after i have made this adjustments but music plays
     
  16. Mryogi23

    Mryogi23

    Joined:
    Feb 2, 2016
    Posts:
    7
    Okay, So I'm on the the second video of the first part and he tells me to rename and move the new animation files. I did just that according to the new patch thing, but when i try to play, the player doesn't show up at all. What did I do wrong? I think I did something wrong since I got an error that says "removing sprite sheet because asset does not exist."
     
    Last edited: Feb 11, 2016
  17. Gorkatan

    Gorkatan

    Joined:
    Sep 6, 2015
    Posts:
    12
    Hello, this is my first message in the forum, so I think the right thing to start with is by saying thank you to Matthew Schell and everybody else who are making this possible. This is a really useful site.

    My question is about the BoardManager. I'm trying to modify the generation of the board focusing more in the maze design than in the real goals of the tutorial (collecting items and avoiding enemies). I'm just trying to make the board bigger and apply some skills I learnt in an Algorithm course to generate a maze.

    So basically, once I finished the whole tutorial I created a new project with the tiles prefabs, the scripts: Loader, GameManager and BoardManager (simplified to just generate the enviroment and not the items and enemies). But, and here comes the problem, some times between the tiles appear some black lines or gaps(since the background is black). Here is an image with the problem:

    What can I be doing wrong? I didn't modify the functions that set the tiles of the board, I didn't modify the sprites and neither the dimensions of the Sprite Renderers. Can anyone give me some clues? Thank you very much for your time
     

    Attached Files:

  18. deviantony

    deviantony

    Joined:
    Feb 27, 2013
    Posts:
    6
    I'm having the same issue at the end of the tutorial, only on black line/gap in the middle of the map.
     
    Gorkatan likes this.
  19. lukicamukica

    lukicamukica

    Joined:
    Feb 11, 2016
    Posts:
    8
    Ok, this is my first question on this forum.
    I am having problems with part 5, to be more precise it seems that when i try to call setupScene function from 'BoardManager' script i get an error.
    Error CS1061 'BoardManager' does not contain a definition for 'setupScene' and no extension method 'setupScene' accepting a first argument of type 'BoardManager' could be found (are you missing a using directive or an assembly reference?)
    Source code(GameManager):
    ---------------------------------------------------------------------------------------------------------------------------------------------------------

    using UnityEngine;

    public class GameManager : MonoBehaviour {

    public BoardManager gameScript;

    int level = 3;

    void Awake () {
    gameScript = GetComponent<BoardManager> ();
    initGame();
    }
    void initGame()
    {
    gameScript.setupScene(level);
    }
    }
    ---------------------------------------------------------------------------------------------------------------------------------------------------------
    As you can see the code is the same as in the video.
    Here is setupScene function from BoardManager script:
    ---------------------------------------------------------------------------------------------------------------------------------------------------------
    public void setupScene(int level)
    {
    boardSetup();
    initialselist();
    layoutObjectAtRandom(wallTiles, wallCount.minimum, wallCount.maximum);
    layoutObjectAtRandom(foodTiles, foodCount.minimum, foodCount.maximum);
    int enemyCount = (int)Mathf.Log(level, 2f);
    layoutObjectAtRandom(enemyTiles, enemyCount, enemyCount);
    Instantiate(exit, new Vector3(columns - 1, rows - 1, 0f), Quaternion.identity);
    }
    }
    }
    ---------------------------------------------------------------------------------------------------------------------------------------------------------
    There you go. It would be awesome if somebody could help me. I've been searching for solution really long time now nd I couldn't find it. If you need more information please tell. I can even do some screenshots.
     
  20. Gorkatan

    Gorkatan

    Joined:
    Sep 6, 2015
    Posts:
    12
    Hi there. I'm not an expert on Unity (yet ;) ), but it seems to me the problem is not in the script. At least I can't find anything wrong. Have you placed both scripts (BoardManager and GameManager) in a dummy GameObject called GameManager? And then have you added that GameObject to the prefabs folder?

    I think it is necessary to keep both scripts in the same GameObject so you let GameManager make a reference to BoardManager.
     
    Last edited: Feb 13, 2016
  21. RazLani

    RazLani

    Joined:
    Jul 23, 2013
    Posts:
    12
    I have a question regarding a Coroutine call inside another: In GameManager we have MoveEnemies method which calls MoveEnemy for each enemy. I've made a few changes to MoveEnemy which now checks to see if Enemy is blocked on x or on y, and moves accordingly. It also checks to see if both x and y are blocked, and if so, will attack the wall.

    In the AttemptMove() method I'm doing the following at the bottom:

    Code (CSharp):
    1. if (hitComponent != null)
    2.             {
    3.                 _coCantMove = OnCantMove(hitComponent, xDir, yDir);
    4.  
    5.                 StartCoroutine(_coCantMove);
    6.             }
    7.  
    8.             _skipMove = true;
    _coCantMove is a private instance field on my Enemy class.

    My OnCantMove Coroutine then starts like so:

    Code (CSharp):
    1. protected IEnumerator OnCantMove<T>(T component, int xDir, int yDir)
    2.         {
    3.             if (component is Wall)
    4.             {
    5.                 while (_xBlocked && _yBlocked)
    6.                 {
    7.                     Wall wallHit = component as Wall;
    8.                     wallHit.DamageWall(WallDamage);
    9.                     _animator.SetTrigger("enemyAttack");
    10.                     SoundManager.Instance.RandomSfx(EnemyAttack1, EnemyAttack2);
    11.                     yield return new WaitForSeconds(MoveTime);
    12.                     MoveEnemy();
    13.                     StopCoroutine(_coCantMove);
    14.                 }
    My question is this: the game seems a little choppy and I'm not sure if that's becuase of the code I've written or if my work pc is slow(this level has 1 enemy: no PC is that bad). The MoveEnemies() is already a coroutine and I've turned OnCantMove into a coroutine which is stored in an instance field so that we resolve the case where x is blocked and y is blocked on that Enemy with that while loop.

    So is my approach flawed? Is it the nature of my lag in-game? Bad design pattern? What should I be looking out for, how to I benchmark these coroutines in Unity, how do I keep track of how many there are? The debugger can only get me so far as there is already a bit of behaviour to track, and I feel I am not fully prepared for all the ramifications of using coroutines before I move on to more advanced behaviour that I desire.

    Please advise!
     
  22. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Hi, have you had a chance to look through the UI Tutorials on the Learn page?, there is a section about the UI and how buttons are put together, might give a good primer on their construction and interaction, then you can see how to incorporate into this project.

    Linky : http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-button?playlist=17111
     
    Matthew-Schell likes this.
  23. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Not sure what causes this, but, in the interim until Matt gets back, try reducing the 'pixels-per-unit' in the main scavanger sprite sheet down from 32 to 31.99, seemed to work for me just now when I tested.
     
    Gorkatan and deviantony like this.
  24. gorillahands4

    gorillahands4

    Joined:
    Jan 14, 2016
    Posts:
    5
    Could someone possible elaborate on this post:

    as well as this reply from Unity on the Youtube comments section:

    Q:
    Whats the point of the loader script and object? Why not just have the GameManager in scene to start the game? Im confused what benefits are gained by manually loading the gamemanager into play.

    Unity:
    A: Because the GameManager is set to DontDestroyOnLoad when we reload the scene we would then have two GameManagers.


    Since the GameManager is a singleton if you were to reload would it not destroy the new instance of the GameManager?
     
  25. TheOriginalMomos

    TheOriginalMomos

    Joined:
    Sep 5, 2013
    Posts:
    4
    So nobody has an idea why I get the Day 1 screen again when I complete the level?

    When I finish the level, it shows "Day 1" again then it doesn't do anything else. It doesn't load the level again. It just stops there.

    EDIT: Well I found out something interesting : If I build the project, everything works just fine for some reasons, but the in-unity play option still breaks after day 1.

    EDIT 2: The same build that works on my laptop doesn't work on my tower (i5 6600)
     
    Last edited: Feb 22, 2016
  26. krippulo

    krippulo

    Joined:
    Jan 29, 2016
    Posts:
    9
    Hello!
    First of all, thanks for that great tool and tutorials.
    I'm new at Unity, although not at programming languages. I've followed the UFO and SpaceShooter tutorials without problems.
    I'm currently at "Enemy Animator Controller" episode and I'm gettíng the following error:
    When trying to move onto an innerWall, the player does nothing.

    I've reviewed the code but couldn't find an error. For this reason I've added a few log lines in my MovingObjects-AttemptMove. It is as follows:
    protected virtual void AttemptMove<T>(int xDir,int yDir) where T:Component{
    RaycastHit2D hit;
    bool canMove = Move (xDir, yDir, out hit);
    if (hit.transform == null)
    return;
    T hitComponent=hit.transform.GetComponent<T>();
    Debug.Log ("canMove="+canMove);
    Debug.Log ("hitTransform="+hit.transform);
    Debug.Log ("hitComponent="+hitComponent);
    if (canMove == false && hitComponent != null) {
    OnCantMove (hitComponent);
    }
    }

    You can see the result of the log lines in the following snapshot: I've hit the "UParrow" key to try to move onto the inner wall with the skull
    upload_2016-2-22_23-31-0.png
    I don't know what I'm doing wrong.
    The hitComponent is always returning blank and, therefore, the OnCantMove routine (which is in charge for changing the Player's animation and damaging the wall) is never executed.

    Please, please, can anybody help?
    Thanks in advance.
    Regards.
     
  27. SteamboaTravis

    SteamboaTravis

    Joined:
    Jan 7, 2016
    Posts:
    1
    Thanks for the Awesome tutorial.

    I am trying to marry this tutorial to the random cave generation tutorial and things seemed to be going well for a while. I have been able to create maps and randomly add objects and the player to these maps, but now I am unable to make the player move. When I hit a directional key or WASD, the player's food score goes down like it should, but the player stays still. My scripts aren't throwing any errors to the console, so it is has been hard to nail down what the problem is. I have used a series of debug.log statements to try to track to problem. It seems that the while loop in the SmoothMovement coroutine never finishes. I tried commenting out the entire SmoothMovement coroutine and using transform.Translate in the Move method but got the same result, food score down, player stays still.

    Some of the differences between my project and the tutorial project that might be relevant are: My player is instantiated through code in the BoardManager script after all of the other gameobjects, my player is composed of three gameobjects with sprite renders parented to another object that holds the scripts and the collider and the rigid body, I never actually imported the tutorial package and have just tried to create my own versions of all of the assets, layers and tags.

    Here is my MovingObject script with the debug statements along with a copy of the console output when I try to move the player:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public abstract class MovingObject : MonoBehaviour {
    5.  
    6.     public float moveTime = 0.1f;
    7.     public LayerMask blockingLayer;
    8.  
    9.     private BoxCollider2D boxCollider;
    10.     private Rigidbody2D rigidBody;
    11.     private float inverseMoveTime;
    12.  
    13.     // Use this for initialization
    14.     protected virtual void Start () {
    15.         boxCollider = GetComponent<BoxCollider2D> ();
    16.         Debug.Log ("Got collider from " + gameObject.tag);
    17.         rigidBody = GetComponent<Rigidbody2D> ();
    18.         Debug.Log ("Got rigid body from " + gameObject.tag);
    19.         inverseMoveTime = 1f / moveTime;
    20.     }
    21.  
    22.     protected bool Move(int xDir, int yDir, out RaycastHit2D hit){
    23.         Debug.Log ("Move called");
    24.  
    25.         Vector2 start = transform.position;
    26.         Vector2 end = start + new Vector2 (xDir, yDir);
    27.  
    28.         boxCollider.enabled = false;
    29.         Debug.Log ("Box collider is " + boxCollider.enabled);
    30.         hit = Physics2D.Linecast (start, end, blockingLayer);
    31.         Debug.Log ("Linecast is " + hit);
    32.         boxCollider.enabled = true;
    33.         Debug.Log ("Box collider is " + boxCollider.enabled);
    34.  
    35.         if (hit.transform == null) {
    36.             StartCoroutine (SmooothMovement(end));
    37.             Debug.Log ("StartCoroutine SmoothMovement");
    38.             return true;
    39.         }
    40.  
    41.         return false;
    42.     }
    43.  
    44.     protected IEnumerator SmooothMovement(Vector3 end)
    45.     {
    46.         Debug.Log ("Coroutine Started");
    47.  
    48.         Debug.Log ("current position is " + transform.position);
    49.  
    50.         Debug.Log("end is " + end);
    51.  
    52.         float sqrRemainingDistance = (transform.position - end).sqrMagnitude;
    53.  
    54.         Debug.Log("sqrRemainingDistance is " + sqrRemainingDistance);
    55.  
    56.         while (sqrRemainingDistance > float.Epsilon) {
    57.             Debug.Log ("SmoothMovement while loop entered");
    58.             Vector3 newPosition = Vector3.MoveTowards (rigidBody.position, end, inverseMoveTime * Time.deltaTime);
    59.             Debug.Log ("newPosition is " + newPosition);
    60.             rigidBody.MovePosition (newPosition);
    61.             sqrRemainingDistance = (transform.position - end).sqrMagnitude;
    62.             Debug.Log ("sqrRemainingDistance is now " + sqrRemainingDistance);
    63.             yield return null;
    64.         }
    65.         Debug.Log ("SmoothMovement while loop finished");
    66.  
    67.     }
    68.  
    69.     protected virtual void AttemptMove <T> (int xDir, int yDir)
    70.         where T : Component
    71.     {
    72.         Debug.Log ("AttemptMove called");
    73.  
    74.         RaycastHit2D hit;
    75.         bool canMove = Move (xDir, yDir, out hit);
    76.  
    77.         if(hit.transform == null)
    78.             return;
    79.  
    80.         T hitComponent = hit.transform.GetComponent<T> ();
    81.  
    82.         if(!canMove && hitComponent != null)
    83.             OnCantMove(hitComponent);
    84.     }
    85.  
    86.     protected abstract void OnCantMove <T> (T component)
    87.         where T : Component;
    88. }
    89.  


    I am really at a loss right now and am considering ditching the whole movement system from the tutorial and just trying to build something else that might achieve the same result, but I would much rather sort out how to make the code I have work. Thanks again for the tutorial.
     
  28. Chairman_Meow

    Chairman_Meow

    Joined:
    Feb 25, 2016
    Posts:
    13
    Pllleeeease help. Can't get around this. I am new to Unity and just started the RogueLike tutorials. I can not figure out my error. I was trying to add GameManager and BoardManager scripts to the GameManager game object but it says:



    Went to the portion of the script with InitialiseList and can not figure it out. Please help! Thank you!
     
  29. krippulo

    krippulo

    Joined:
    Jan 29, 2016
    Posts:
    9
    Hi, Grandal.
    To provide a proper answer, it would be nice to see the code of your 'BoardManager' script.
    Anyway, as for the content of the error message, maybe you've misspelled the function 'InitialiseList()' on its declaration? You could have changed capitalization, or toggled any letter ...
    Hope this helps.
    Regards.
     
    Matthew-Schell likes this.
  30. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    Regarding black lines I believe that the issue disappears if you set the aspect ratio of the Game View to 16x9 or another fixed aspect ratio. They also should not appear in builds of the game, only in the editor.
     
  31. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    A general few general comments here: if you are trying to modify the tutorial or move beyond it's original scope, feel free to post here looking for solutions from your peers but I will not be able to help with this. I can answer questions related to the original tutorial content. I cannot debug other new or changed scripts you guys have written.

    Regarding people saying "I'm new and I don't understand this". If you haven't done either Roll A Ball or 2D UFO and Space Shooter or Survival Shooter (preferably both) please do not attempt this tutorial. This is an intermediate tutorial that contains intermediate scripting concepts. It's not intended for people who are new to scripting and is probably too difficult as a place to start. I tried to be clear about that in the tutorial but am re-stating that again here since a lot of people seem to not understand. I cannot teach you the scripting skills you need to understand this in a forum post. I recommend you pause your work on this and complete the beginner appropriate tutorials first.
     
  32. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    Yes you're correct, if we had a GM in the scene a new one would be destroyed, as per the singleton pattern. In this case I believe it would be fine to just place the object in the scene, if you prefer that approach.
     
  33. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    So in this case it seems that for some reason the component is null. My best guess is that the component you are looking for is not attached to that object? Or you are not checking for the correct component type? There should be a Wall script attached to the wall and your script should be checking for a Wall when you call AttemptMove.
     
  34. krippulo

    krippulo

    Joined:
    Jan 29, 2016
    Posts:
    9
    Thanks for your reply.
    I've checked what you suggested.
    Regarding to your second suggestion (checking for a Wall when you call AttemptMove): according to my calling code in 'Player'
    voidUpdate(){
    if(!GameManager.instance.playersTurn)
    return;
    inthorizontal=0;
    intvertical=0;
    horizontal=(int)Input.GetAxisRaw("Horizontal");
    vertical=(int)Input.GetAxisRaw("Vertical");
    if(horizontal !=0)
    vertical=0;
    if(horizontal !=0 || vertical !=0){
    AttemptMove<Wall>(horizontal,vertical);
    }
    }
    protected override void AttemptMove<T>(intxDir,intyDir){
    RaycastHit2D hit;
    food--;
    base.AttemptMove<T>(xDir,yDir);
    CheckIfGameOver();
    GameManager.instance.playersTurn=false;
    }

    seems to be right. And, of course, I've checked that the "base" class is 'MovingObject'.
    Anyway, I've made a temporary change in the called code of 'MovingObject' just to ensure that it looks for Wall
    protected virtual void AttemptMove<T>(intxDir,intyDir) where T:Component{
    RaycastHit2Dhit;
    boolcanMove=Move(xDir,yDir,outhit);
    if(hit.transform==null)
    return;
    Wall hitComponent=hit.transform.GetComponent<Wall>();
    //T hitComponent=hit.transform.GetComponent<T>();
    Debug.Log("canMove="+canMove);
    Debug.Log("hitTransform="+hit.transform);
    Debug.Log("hitComponent="+hitComponent);
    if(canMove==false && hitComponent !=null){
    OnCantMove(hitComponent);
    }
    }

    and it still reports hitComponent null although (in relation to your first suggestion), as it is shown in the screenshot, the object I'm trying to move to has a Wall component (there is only one Wall7Clone in the scene and its components are shown on the debug tab)
    upload_2016-2-25_20-9-46.png
    Is it important that the Local Identifier In File property of the script is equal to 0? It is also 0 in the rest of the walls but not in the player's script.
    What does it mean? I've been looking for information on the manual pages without much success.
    By the way, Im working with Unity 5.3.2 on Ubuntu.
    Regards.
     
  35. gorillahands4

    gorillahands4

    Joined:
    Jan 14, 2016
    Posts:
    5


    I actually went off and tried it and as you said it did indeed remove any newly created GM's But without using your loader approach, anything beyond level one had multiple boards stacked on top of each other. (E.g. level 2 will have 3 instances of board instead of 1). I believe I understand what is happening but could you correct me if I am wrong:

    Level 1: Since this is the first level, the singleton GM already being present in the scene will not have any adverse effects without the loader.
    Level 2: The scene reload is called and a new GM is created, but since it is not the singleton it will be destroyed. A problem arises though since it will not be destroyed until the first Update is called. So this newly created GM will still call it's InitGame from Awake as well as InitGame again via OnLevelLoaded, thus creating two instances of boards. The singleton will also call it's InitGame from the OnLevelLoad function, stacking a total of 3 boards onto one area.

    Am I understanding the Destroy(GameObject) correctly? Does it wait until Update is called allowing this second GM to still execute it's Awake and OnLevelLoad?

    Thanks again for the tutorial by the way, I'm new to all this stuff and it's been really interesting learning these different design patterns!
     
    Last edited: Feb 26, 2016
  36. Chairman_Meow

    Chairman_Meow

    Joined:
    Feb 25, 2016
    Posts:
    13
    Thanks for replying back! So here is my code. I initially thought it was a misspelling too but it doesn't look like it on my end. Anyway here is my code:



    Any help would be appreciated. THanks!
     
  37. gorillahands4

    gorillahands4

    Joined:
    Jan 14, 2016
    Posts:
    5
    Your function name (@ line 39) is spelled InitializeList. When you call the function (@ line 90) you spelled it InitialiseList();

    Change the z to a s at line 39 and you should be good to go!
     
  38. tarod-net

    tarod-net

    Joined:
    May 29, 2015
    Posts:
    8
    Hello Matthew,

    When I was working with the tutorial I got the same problem also in the game, not only the editor, so I was looking for a solution. I applied the next one:

    http://answers.unity3d.com/questions/599038/black-lines-between-tile-sprites.html#comment-1128366

    What do you think about it?

    Thanks!
     
  39. krippulo

    krippulo

    Joined:
    Jan 29, 2016
    Posts:
    9
    SILLY ME!!!
    First of all, thanks to those who have had a look at my issue and sorry for making you loose your time (as mine):
    As the project was downloaded with a fistfull of "Completed assests", I mixed some of them with the ones I am building as part of the tutorial. Now, I've removed the "Completed assests" from the project and reassigned mines.
    Now, everything works fine.

    Lesson for me to learn: from now on, on every downloaded tutorial package, move the completed assets outside the project folder.

    Issue closed.
    Regards.
     
  40. Chairman_Meow

    Chairman_Meow

    Joined:
    Feb 25, 2016
    Posts:
    13
    OMG!!!! You did it!!! LOL I had no clue. As you can tell I am new to programming so this is kind of embarrassing. And you weren't here to hear me say it but I let out a big "WOOOOH!!!" Thank you so much!
     
    gorillahands4 likes this.
  41. Chairman_Meow

    Chairman_Meow

    Joined:
    Feb 25, 2016
    Posts:
    13
    So I have another question. My variables for the player are not showing up in the inspector. I went through and double checked code and it looks fine to me. I have also saved and gone into the Assets > Refresh but the compiler still wont show anything. Here is my code:



    Here is what I get in the compiler:



    So as you can see there is nothing showing. From the video it looks like there is supposed to be:

    Move Time
    Blocking Layer
    Wall Damage
    Points Per Food
    Points Per Soda
    Restart Level Delay

    Thank you in advance for the help!
     
  42. gorillahands4

    gorillahands4

    Joined:
    Jan 14, 2016
    Posts:
    5
    You have a syntax error at line 14, should be protected instead of just protect. The little red line between void and Start was an indicator that there is a problem in your code.
     
  43. Chairman_Meow

    Chairman_Meow

    Joined:
    Feb 25, 2016
    Posts:
    13
    Nice! Thank you so much! It worked and I am back at it!
     
  44. Chairman_Meow

    Chairman_Meow

    Joined:
    Feb 25, 2016
    Posts:
    13
    OK So I am on the end of video 12 and I am getting this error:



    After clicking the error it brings me to my Player Script and highlights the following code:



    Everything seems ok from what I can see. Can someone help me out please? Thank you in advance!
     
  45. gorillahands4

    gorillahands4

    Joined:
    Jan 14, 2016
    Posts:
    5
    Did you drag the FoodText instance from the Scene Hierarchy into the appropriate Food Text field on the Player's script component? Null Reference means you tried to access something that isn't there, i.e. you tried to use foodText but it does not have a reference to a Text object.
     
    Flagusco likes this.
  46. SMX_82

    SMX_82

    Joined:
    Feb 29, 2016
    Posts:
    2
    I don't know if this is still operative or not but.. I'm following the tutorial on how to make a 2D roguelike game and I'm having an issue on loading my game. Everything loads perfectly but floor tiles which doesn't load and appear only in black, as if they were a background...
    Can someone help me identifying the problem??
    Thanks!!
     
  47. Chairman_Meow

    Chairman_Meow

    Joined:
    Feb 25, 2016
    Posts:
    13
    Oh damn. Such a small error. Thats exactly what it was. It is fixed and I have an almost complete game. Thank you again. You are like my sensei.
     
  48. krippulo

    krippulo

    Joined:
    Jan 29, 2016
    Posts:
    9
    @SMX_82

    Probably you haven't attached the corresponding Sprite on the SpriteRenderer component.
    Please, review this component on each of the FloorX prefabs (X=1 to 8).
    Hope this helps.
    Regards.
     
  49. SMX_82

    SMX_82

    Joined:
    Feb 29, 2016
    Posts:
    2
    Everything seems to be ok, but still doesen't work, I only see black spaces...
     
  50. Marchpane

    Marchpane

    Joined:
    Jul 22, 2014
    Posts:
    2
    When working on the last part of Section 3.2 of the tutorial, 'Creating Destructable Walls', my SpriteSheet only has seven damaged wall sprites to add to my eight wall prefabs.

    Have I done something wrong somewhere, or have others noticed this?
     
Thread Status:
Not open for further replies.