Search Unity

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

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

    FireHawkX

    Joined:
    Apr 26, 2016
    Posts:
    28
    I've been trying for QUITE A WHILE to make things "NOT LAG" (or actually remove the slowdown) when more and more zombies show up... I went through ALL 16 pages here, did ton of searches on google...

    I cannot believe nobody ever suggested this... which is why i'm writing it here for other who might come search for an answer!! :)

    As stated many times in the previous pages, setting turndelay on the gamemanager anywhere below 0.1 makes everything bug pretty seriously... so i left it at 0.1... however, with any number of zombies you could REALLY notice the difference in speed the game slowed to a crawl...

    There is however a move speed for the zombies themselves, which is attached on both enemies prefab...
    So going to both Enemy1 and Enemy2 prefab and changing Move TIME to 0.01 ... i was able to get up to lvl 26 and never noticed any slowdown at all!! in fact, no bug, no problem, no issue, nothing! I was expecting zombies to walk all over each other and the game to get quite broken as more and more would appear.... yet it stayed PERFECT!

    So the solution is to reduce move time of both enemy prefab to 0.01 (or anywhere you want) and it reduce the lag between turns!! :)

    Hope it help out others in my situation looking for a fix!!
     
  2. The_Rod

    The_Rod

    Joined:
    Jun 8, 2015
    Posts:
    2
    Hey guys, thanks for all the info in this thread. There's a lot of good stuff here.

    I am having an issue of my own. I just completed Part 11 (Enemy Animator Controller) and something happened to the game board. It no longer generates at all while the Player object still appears. The idle animation is still there and I can move once before I can't do anything else (and the animation goes back to idle).

    All of the code is taken from the tutorial pages and should be exactly the same. The only error message I get from the console refers to the "InitGame" function from the "GameManager" script (shown in the screenshot). It reads:

    "NullReferenceException: Object reference not set to an instance of an object"

    The error is referring to the
    Code (csharp):
    1. enemies.Clear();
    in "InitGame", shown here:

    Code (CSharp):
    1. void InitGame()
    2.     {
    3.         enemies.Clear();
    4.         boardScript.SetupScene(level);
    5.     }
    Also, is the GameManger(Clone) supposed to be in the Hierarchy? That's where the error is happening, according to the console.

    Any help would be very much appreciated. While I'm not new to programming, I am new to Unity and C# so this thing is going over my head a little bit. I'm using Unity 5.3.5f with Visual Studio 2015.

     
  3. Rockyeahh

    Rockyeahh

    Joined:
    May 19, 2016
    Posts:
    17
    Hi I'm halfway through part 5 and the guy says to press play at around 3:24 but my screen shows one piece of the map far away, rather than the complete level that should have been generated.
    It gives me an error that says 'Argument is out of range'.

    I'm copying the two scripts in as text and I can't post screens shots as it doesn't seem to be working right now.

    gamemanager script:

    using UnityEngine;
    using System.Collections;

    public class GameManager : MonoBehaviour {

    public BoardManager boardScript;


    private int level = 3;

    // Use this for initialization
    void Awake ()
    {
    boardScript = GetComponent<BoardManager>();
    InitGame();
    }

    void InitGame ()
    {
    boardScript.SetupScene(level);
    }

    // Update is called once per frame
    void Update () {

    }
    }

    Boardmanager script:

    using UnityEngine;
    using System;
    using System.Collections.Generic;
    using Random = UnityEngine.Random;

    public class BoardManager : MonoBehaviour
    {
    [Serializable]
    public class Count
    {
    public int minimum;
    public int maximum;

    public Count (int min, int max)
    {
    minimum = min;
    maximum = max;
    }
    }

    public int columns = 0;
    public int rows = 0;
    public Count wallCount = new Count(5, 9);
    public Count foodCount = new Count(1,5);
    public GameObject exit;
    public GameObject[] floorTiles;
    public GameObject[] wallTiles;
    public GameObject[] foodTiles;
    public GameObject[] enemyTiles;
    public GameObject[] outerWallTiles;

    private Transform boardHolder;
    private List<Vector3> gridPositions = new List<Vector3>();

    void InitialiseList()
    {
    gridPositions.Clear();

    for (int x = 1; x < columns-1; x++)
    {
    for (int y = 1; y < rows-1; y++)
    {
    gridPositions.Add(new Vector3(x, y, 0f));
    }
    }
    }


    void BoardSetup ()
    {
    boardHolder = new GameObject("Board").transform;

    for (int x = -1; x < columns + 1; x++)
    {
    for (int y = -1; y < rows + 1; y++)
    {
    GameObject toInstantiate = floorTiles[Random.Range(0, floorTiles.Length)];
    if (x == -1 || x == columns || y == -1 || y == rows)
    toInstantiate = outerWallTiles [Random.Range (0, outerWallTiles.Length)];

    GameObject instance = Instantiate(toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;

    instance.transform.SetParent(boardHolder);
    }
    }
    }

    Vector3 RandomPosition()
    {
    int randomIndex = Random.Range(0, gridPositions.Count);
    Vector3 randomPosition = gridPositions[randomIndex];
    gridPositions.RemoveAt (randomIndex);
    return randomPosition;
    }

    void LayoutObjectAtRandom(GameObject[] tileArray, int minimum, int maximum)
    {
    int objectCount = Random.Range(minimum, maximum + 1);

    for (int i = 0; i < objectCount; i++)
    {
    Vector3 randomPosition = RandomPosition();
    GameObject tileChoice = tileArray[Random.Range(0, tileArray.Length)];
    Instantiate(tileChoice, randomPosition, Quaternion.identity);
    }
    }

    public void SetupScene (int level)
    {
    BoardSetup();
    InitialiseList();
    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);
    }
    }
     
  4. Simpso

    Simpso

    Joined:
    Apr 20, 2015
    Posts:
    158
    Fixed..
    It was the onlevelloaded bug others have spoke about in his thread.

    Hey guys, any help here.
    Been through the whole tutorial and everything work great in the Editor.
    After porting to an android device however for some reason the game starts on Day 2.
    After completing Day 2 jumps on to day 4 with 0 food.

    Complete loss as to what is causing this.
    Also anyone have any best practices on how to debug a mobile game. Possible to do without having to export everytime?

    Thanks
     
    Last edited: Jun 13, 2016
  5. steadmuffin

    steadmuffin

    Joined:
    Jun 1, 2016
    Posts:
    49
    Is there a point in the tutorial where we learn how to configure inputs to move the player? I just finished the EnemyAnimationController Tutorial which the instructor tests out by moving the player.I have no recollection of when he explained how to move the player.

    EDIT 1: I just accessed the Input Manager and saw that movement inputs are already configured. When I press the buttons though, nothing happen. Anyone have ideas?

    EDIT 2: I figured why my player couldn't move. The script was not enabled on the prefab.
     
    Last edited: Jun 17, 2016
  6. ClockWise

    ClockWise

    Joined:
    Jun 19, 2013
    Posts:
    2
    I believe the issue is that you have specified an empty board. Set a value to both columns and rows. The single tile you're seeing is probably 1 instance of the outer wall, I assume. Hope it helps!
     
  7. ClockWise

    ClockWise

    Joined:
    Jun 19, 2013
    Posts:
    2
    I have a general request here. I'd like to continue on this game but rather have the user attack manually by pressing a button, and then attack in the direction the user is facing. I want this behaviour for different kinds of enemies as well, but I'm not sure on the best approach on how to do this. I've been thinking on adding a collider on the front face of the player (and enemies) and check on collision hits from that collider - which sounds like a reasonable approach to me.

    However, I'd like to use the same inheritance behaviour we used for MoveObject (AttemptMove<T> ()) so I can simply just add a script to any given entity and it will be able to attack. But I can't, of course, inherit from several classes at the same time, so now I'm stuck trying to figure out how to do this in the cleanest, easiest, and modular way. Any suggestions or examples anyone can show me? Right now the only thing I can think of is writing some sort of components which handles this logic to which I add to each entity I want to use it on.

    Sincerely,
    ClockWise

    Edit 1:
    I ended up making a component which handles attacking and all it does it handles attack cooldown, attacking time, and attack damage (rather than having it in player as in these tutorials). In each class which can be hit I handle all I need to do is to get the AttackComponent from the Colliders parent in OnTriggerEnter2D(), cast it, and withdraw the attack damage.

    Hope this helps someone.
     
    Last edited: Jun 18, 2016
  8. Rockyeahh

    Rockyeahh

    Joined:
    May 19, 2016
    Posts:
    17
    It worked, you are awesome!
     
  9. steadmuffin

    steadmuffin

    Joined:
    Jun 1, 2016
    Posts:
    49
    Does anyone have the problem where the player is able to move while the board is setting up?
     
  10. Davvv06

    Davvv06

    Joined:
    Jul 16, 2016
    Posts:
    2
    Hi all,

    Thanks Matthew for the tuto, very clear in spite of non-obvious content, which I guess was the goal af a 'intermediate-level' one.

    I experienced a bug: boards duplicated at each new level, ending up with huge mess on the screen. Seemed to be related to OnLevelWasLoaded, this topic apparently was discussed earlier on the forum. I don't know if it's the same issue, but for on my side I simply deleted the GameManager from the hierarchy and let the loader instantiate it - this solved the issue.

    Oh, and there's also this warning about SceneManager to be used instead of LoadLevel, to get rid of. Quite easy to do but it might be nice to update the tuto.

    Now, I had another bug in-game : it happened that two zombies could end up superposed on the same tile, then stuck because of 2Dcolliders. Having a look at the code I understood, that it was somehow due to the physics LineCast who didn't detect that another character was moving to the same destination tile more or less at the same time. I fixed that by instantiating at destination tile a kind of 'invisible wall' during the call to the SmoothMovement method. It has no sprite renderer but a is part of Blockling Layer, which makes it detected by other characters who plan to move at the same place, and prevents the dubious move from happening. Then the invisible wall is destroyed. 2 lines of code added, plus the gameobject in the editor. It's probably a quite unefficient & ugly solution (I'm new to Unity, since this week), so I'd be happy to know if there's a better fix, if any of you encountered this and has something else to suggest.

    Thanks !
     
  11. xgbj

    xgbj

    Joined:
    Jul 18, 2016
    Posts:
    1
    Hello everyone,
    does anyone meet the situation that the player cannot move when its start position was (0,0,0) . I follow the tutorials until the part 11, I find that the player cannot move (the enemies work well with the input). the debugger shows that the player was stacked at the start position , I changed the start position (0,0,0) to (1,0,0) . the player can move now, but player cannot get through the position(0,0,0) which was floor in the map , it seems that the object at (0,0,0) becomes to be a collider object. But I don't know where the code makes it happened. I even copied the BorderManage.cs in the completed folder to my project, but I still have the problem.
    Any help would be appreciated. I'm new to Unity and C#. version: Unity 5.3.5f with VS 2015.
     
  12. Lionel_Leeser

    Lionel_Leeser

    Joined:
    Jan 29, 2015
    Posts:
    2
    Hi, there.

    I searching where the reload of the scene occurs ? I just can't find it !


    Please help it's the last little thing I need to understand :D


    Thanks in advance !
     
  13. OmarK

    OmarK

    Joined:
    Mar 17, 2015
    Posts:
    11
    Quick question. In the Board Manager script, under the method LayoutObjectAtRandom, why are we using Random.Range(minimum, maximum +1) rather than Random.Range(minimum, maximum) without adding 1 to maximum? Random.Range produces a random number between minimum and maximum with both of them being inclusive, so why is the +1 necessary?

    Script can be found here https://unity3d.com/learn/tutorials...tutorial/writing-board-manager?playlist=17150
     
    Last edited: Jul 19, 2016
  14. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Afternoon.

    Random.Range has two overloads so can be used with float or int values.

    using it with float values, you are correct in that the min and max is inclusive.

    taken from Docs (you have to scroll down to see in the info for the Int parameters)

    public static float Range(float min, float max);

    Returns a random float number between and min [inclusive] and max [inclusive] (Read Only).
    Note that max is inclusive, so using Random.Range( 0.0f, 1.0f ) could return 1.0 as a value.



    public static int Range(int min, int max);
    Returns a random integer number between min [inclusive] and max [exclusive] (Read Only).
    Note that max is exclusive, so using Random.Range( 0, 10 ) will return values between 0 and 9. If max equals min, min will be returned.

    so if you wanted the last integer to be included, you would have to add one to it.
    Hope that helps a bit, I know its not clear when looking at the top of the scripting reference for it, but you would have to scroll down to find it underneath.

    https://docs.unity3d.com/ScriptReference/Random.Range.html
     
    OmarK likes this.
  15. OmarK

    OmarK

    Joined:
    Mar 17, 2015
    Posts:
    11
    This makes much more sense now. Thank you!
     
  16. rewb0rn

    rewb0rn

    Joined:
    May 17, 2016
    Posts:
    11
    Hello, I compiled the game for WebGL and it works fine. However the graphics are no longer pixel perfect but blurry instead. I assume that what I am seeing is bilinear filtering, but where can I make WebGL not apply it?

    Thanks
     
  17. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Not sure, one thing to try might be

    have a look under Edit > Project Settings > Quality.

    Under rendering, see what the texture quality setting is, try it on Full Res.
     
  18. rewb0rn

    rewb0rn

    Joined:
    May 17, 2016
    Posts:
    11
    Hmm no, it was already on Full Res. I also increased available memory, but without effect. Anything else that might cause this blur or filtering on the WebGL texures?

    Thanks
     
  19. off99555

    off99555

    Joined:
    Jul 25, 2016
    Posts:
    2
    Why the chop sound only work 3 times when the wall has hp = 4?
    I know the reason is footstep sound immediately replaces the chop sound but you must have a way to get around this. I would love both sound to play at the same time.
     
  20. ZeroDeng88

    ZeroDeng88

    Joined:
    Aug 16, 2016
    Posts:
    1
    HI.When i import the asset into the unity,it have an error call :
    "EditorOnlyPlayerSettings property UNet_ServiceEnabled::UNet_ServiceEnabled not inititalized. Please initialize it using corresponding PlayerSettings.InitializeProperty function!
    UnityEditor.Web.JSProxyMgr:DoTasks()"

    Is it something wrong with the setting?My unity version is 5.4.And i found the ProjectSetting.asset cant import into the unity and then the error come.
     
  21. sadaf550

    sadaf550

    Joined:
    Jul 4, 2016
    Posts:
    9
    hi, first of all THANK YOU! I loved the tutorial, its pretty fast tho, but well thanks to the pause button, I could followup :D
    and secondly, I am having this issue, that I cant move on to the NEXT level, it starts with day one, does pretty well, when I reach the exit, it flashes the black background showing "Day 1" again, yet the level wont start or should I say, its stuck at tht moment...
    I think there must be some issue with my game manager script,

    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 BoardManager boardScript;
    10.     public float turnDelay = 0.1f;
    11.     public static GameManager instance = null;
    12.     public int playerFoodPoints = 100;
    13.     [HideInInspector] public bool playersturn;
    14.  
    15.  
    16.     private int level = 1;
    17.     private List<Enemy> enemies;
    18.     private bool enemiesMoving;
    19.     private Text levelText;
    20.     private GameObject levelImage;
    21.     private bool doingSetup;
    22.  
    23.     // Use this for initialization
    24.     void Awake ()
    25.     {
    26.         if (instance == null)
    27.             instance = this;
    28.         else if (instance != this)
    29.             Destroy (gameObject);
    30.         DontDestroyOnLoad (gameObject);
    31.         enemies = new List<Enemy>();
    32.         boardScript = GetComponent<BoardManager> ();
    33.         InitGame ();
    34.     }
    35.     private void OnLevelLoaded (int index)
    36.     {
    37.         level++;
    38.         InitGame ();
    39.     }
    40.  
    41.     public void GameOver()
    42.     {
    43.         if(level<=1)
    44.             levelText.text = "You starved after day " + level;
    45.         else
    46.             levelText.text = "You starved after " + level + " days!";
    47.         levelImage.SetActive (true);
    48.         enabled = false;
    49.     }
    50.  
    51.     void InitGame()
    52.     {
    53.         doingSetup = true;
    54.         levelImage = GameObject.Find ("LevelImage");
    55.         levelText = GameObject.Find ("LevelText").GetComponent<Text>();
    56.         levelText.text = "Day " + level;
    57.         levelImage.SetActive (true);
    58.         Invoke ("HideLevelImage", levelStartDelay);
    59.  
    60.         enemies.Clear ();
    61.         boardScript.SetupScene (level);
    62.     }
    63.  
    64.     private void HideLevelImage()
    65.     {
    66.         levelImage.SetActive (false);
    67.         doingSetup = false;
    68.     }
    69.  
    70.     // Update is called once per frame
    71.     void Update ()
    72.     {
    73.         if (playersturn || enemiesMoving || doingSetup)
    74.             return;
    75.  
    76.         StartCoroutine (MoveEnemies());
    77.     }
    78.  
    79.     public void AddEnemiesToList(Enemy script)
    80.     {
    81.         enemies.Add (script);
    82.     }
    83.  
    84.     IEnumerator MoveEnemies()
    85.     {
    86.         enemiesMoving = true;
    87.         yield return new WaitForSeconds (turnDelay);
    88.         if (enemies.Count == 0)
    89.         {
    90.             yield return new WaitForSeconds (turnDelay);
    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.  
    It also give s this warning to use scene manager to change the level..
    I am using unity 5.3;

    Sooner the help arrives, the better :D
    Thank you in advance :))
     
  22. KeeperOfWonderland

    KeeperOfWonderland

    Joined:
    Aug 24, 2016
    Posts:
    1
    Hello. I am a novice with Unity, started recently. Thank you for a great tutorial. I just finished it.
    Now I experiment with exporting сompleted tutorial-project on my Android device.

    Maybe now it is no longer relate to tutorial topic, but...

    How to turn off this effect, which compresses graphics? (On screenshot)
     
  23. Sky1988

    Sky1988

    Joined:
    Aug 25, 2016
    Posts:
    9
    i'm using unity 5, after i followed every step in the tutorial 5, i got this problem there are gaps between those tile, how do we fix this?
     
  24. Sky1988

    Sky1988

    Joined:
    Aug 25, 2016
    Posts:
    9
    i'm using unity 5, after i followed every step in the tutorial 5, i got this problem there are gaps between those tile, how do we fix this?
     

    Attached Files:

  25. Sky1988

    Sky1988

    Joined:
    Aug 25, 2016
    Posts:
    9
    hi bro, i got a problem in tutorial 5, how do we fix the gap between the tile, im on tutorial 5.
     
  26. Thedar99

    Thedar99

    Joined:
    Aug 27, 2016
    Posts:
    1
    Hello I am trying to download the assets for this game and Unity does not let me, I am using Unity 5.4.
     

    Attached Files:

  27. lefel

    lefel

    Joined:
    Aug 28, 2016
    Posts:
    1
    Hi everybody,

    I have got a little problem with the chapter 13 of this tutorial, on audio and sound manager.

    On the video, at 7:55, the person calls the function Move() in a if statement to check if the player can move and so play the matching sound effects.
    But when we called this function, we can know if the player can move, but in the case player can move, we also execute the movement (by calling the coroutine SmoothMovement() )
    And, in the player script, in AttemptMove(), where we add this call to Move(), we called the base.AttemptMove() function juste before, which called also the Move() function, so our player move twice !

    I don't understand how it can works on the video, because in my case, I got the behavior described above.

    Can you give me an explanation please ?

    (I compared my scripts with the scripts in the video and the scripts given in the "Completed" folder provided with the asset, I did not find problem)

    Regards
     
  28. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71
    Hello All,

    There's something missing in my work, because I went through all the steps up until UI, but when I hit play the player won't move. not with any key I've tried or the mouse. Is it something that the tutorial is not talking about? What am I missing here? Which script specify on this matter?

    Thanks
     
  29. TheTuringMachine

    TheTuringMachine

    Joined:
    Aug 30, 2016
    Posts:
    5
    Hey guys! I was working through this tutorial and after finishing the mobile touch controls section I ran into some weird issues.

    So when I build and deploy the game to my android device, the day screen shows up and so does the food count, but none of my sprites show up. I can press the screen and move around and I hear the character moving and hitting walls and picking up items, but I can't see any of it. I can even progress past day 1 and see the day 2 screen, but nothing is ever shown on the screen past what is on the canvas. Does anyone know what I might be missing/doing wrong?

    It should be noted that I am running Android N but that I also tested it on a lollipop device to no avail. Attached should be a screenshot of the screen only showing the food count.
     

    Attached Files:

  30. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    Just download them anyway, they will in fact work. The videos were done with Unity 5.0.
     
  31. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    My best guess would be that the image that blocks out the play field is not getting disabled by the GameManager. Make sure that the HideLevelImage() function is being calld and that levelImage is being set to inactive at the appropriate moment.
     
  32. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    Without more information I would just recommend checking your work against the completed scene to see if there is anything obvious you missed. You should be able to move using the arrow keys on the keyboard.
     
  33. TheTuringMachine

    TheTuringMachine

    Joined:
    Aug 30, 2016
    Posts:
    5
    Ok, I'll check when I get home.

    Edit: So it looks like my camera positioning got off somehow. Is there a way to make the board fill the camera? It overfills the screen on portrait mode, but landscape is fine.
     
    Last edited: Aug 31, 2016
  34. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71
    I'm at the end of stage 9 out of 14: "player script"
    and I get the "NullReferenceException: Object reference not set to an instance of an object Player.OnDisable () (at asset/scripts/player.cs:28 and sc:34).

    Shouldn't the player be able to move by now?

    Thank you!
     

    Attached Files:

  35. TheTuringMachine

    TheTuringMachine

    Joined:
    Aug 30, 2016
    Posts:
    5
    I don't know if this helps, but whenever I got null reference exceptions it was usually because I didn't drag the appropriate script, file, etc into the slot for it in the player script component in the player object. Also, it helps to make sure you are saving and updating your prefabs, I had a few moments where my player prefab didn't have all of my scripts or files plugged in, but the player object in my scene did.
     
  36. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71
    Hi TheTuringMachine,
    Let's see, the player scrist is attached to the player prefab. The BoardManager and the GameManager is attached to the GameManager. the Loaded script attached to the camera. the Wall scripts and the MovingObject script - not attached to anything. and it won't let me attach the MovingObject script to the player because the class doesn't fit... since abstract.

    the animations are working.

    yeah, a reference is missing... but how do I link this back?
    ....like getting an offline clip in video editing...
     
  37. TheTuringMachine

    TheTuringMachine

    Joined:
    Aug 30, 2016
    Posts:
    5
    looking at the code you attached, it seems like you are getting a null error on this line:

    Code (CSharp):
    1. private void OnDisable()
    2.     {
    3.         GameManager.instance.playerFoodPoints = food;
    4.     }
    which would lead me to believe that your GameManager.instance is null. There are a couple of potential causes for this, so make sure that your GameManager is being loaded in and not being set to null or destroyed at some point. Double check your GameManager initialization.
     
  38. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71
    Hi hi,

    How do you check GameManager initialization? or how do I see if my script is loaded?

    thanks
     
  39. TheTuringMachine

    TheTuringMachine

    Joined:
    Aug 30, 2016
    Posts:
    5
    Do you remember earlier on in the tutorial where we set up GameManager.instance = this? This is where we say that we want a single reference-able version of our GameManager. With that stuff we also created some lines like DontDestroyOnLoad() for our GameManager.instance, and then we would Destroy() any version of our game manager that might be created later. It is possible that one of those lines is being called when they aren't supposed to.

    The best way to see if code is being run is to put some Debug.Log("your text here") lines in to see if they create output to the console. If you post up your GameManager file I can try to look over it when I get some free time if you still need the help.
     
  40. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71
    Thanx a lot, I'll look in to it.
     
  41. BlueBlane

    BlueBlane

    Joined:
    Sep 28, 2015
    Posts:
    70
    One thing I'm really eager to solve is room collisions so rooms don't intersect with each other. Does anyone have a good way of doing this?

    Right now I'm doing the following:
    1. When a room's Setup() function is called upon creation, it checks every tile of the current room against every tile of other rooms. If any one of these tiles is the same instance, a collision flag is set to true.

    2. If the flag is true, I delete the room, and the corridor leading into that now-deleted room gets rotated 90 degrees, and once again the room is created. I do this only once to ensure it doesn't get stuck in an infinite loop.

    Now this helps reduce the chance of rooms colliding quite a bit really, but maybe 1 in every 10 generations, there will be some really large rooms (which are just many rooms colliding with each other).

    The only other way I can think of is to redo the entire generation process if a collision is detected, but this could significantly increase loading times.

    When you design content on a per-room basis, it becomes very difficult to make it work when rooms collide, so ideally I'd want to stop rooms from colliding period.

    I'd be really grateful for any help on this.
     
    Last edited: Sep 3, 2016
  42. Mordetherelicor

    Mordetherelicor

    Joined:
    Aug 28, 2016
    Posts:
    2
    I'm finished up to the "writing the player script" part of the tutorial (part 9 I think), and for some reason I am getting errors saying all of my protected override void's are wrong and that what they are using isn't actually used. I've checked over for spelling and punctuation errors but don't see any and as far as I can tell things are the same as the source code listed on the page (minus notes). Is there something I'm missing elsewhere that's preventing me from attaching this script? or should I simply move to the next one and get all the code in and then make sure to attach it properly? I get the feeling that a lot of this is setting things up to be used elsewhere.

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

    PCGenius101

    Joined:
    Aug 21, 2016
    Posts:
    1
    I built the app using XCode to an iPad Mini and everything worked fine except the touch controls. They would respond to anything I did. I triple-checked the touch script but everything is exactly the same. Could anybody help me? Thanks!
     
  44. Johnny_13

    Johnny_13

    Joined:
    Sep 6, 2016
    Posts:
    1
    hi, i'm having an issue, i've followed and recheked all the tutorials (aside from the mobile controls one) and my player does not collide with walls or enemies. i have checked the box collider sizes, but it never collides. he can pickup food and go to the exit fine, but just glides over walls and enemies. he can even leave the level....... enemies attack the player as he glides over them and does not collide. so i don't know what's happening. help!?
     
  45. DarthSal

    DarthSal

    Joined:
    May 17, 2015
    Posts:
    3
    Hey really enjoyed the tutorial and would love if you could solve a problem I'm having with SmoothMovement() So i have been trying to debug this to no avail. I have increased the rows and columns to 100 so that may be messing with the path-finding of sqrRemainingDistance when reducing the rows and columns back to default the problem is still there. So my enemies are not moving. xDir is -1 and regardless not one is moving up and down. please help I have not messed with any of the movement. much love and sorry to be long winded. Any help is welcomed
     
  46. DarthSal

    DarthSal

    Joined:
    May 17, 2015
    Posts:
    3
    Never Mind i crushed it
     
  47. Sky1988

    Sky1988

    Joined:
    Aug 25, 2016
    Posts:
    9
    recently i got those warning message in the console after i open the project, can anyone tell me how to solve this?
     

    Attached Files:

  48. Sky1988

    Sky1988

    Joined:
    Aug 25, 2016
    Posts:
    9
    can anyone explain to me what does serializable do? i dont understand

    using UnityEngine;
    using System;
    using System.Collections.Generic; //Allows us to use Lists.
    using Random = UnityEngine.Random; //Tells Random to use the Unity Engine random number generator.

    namespace Completed

    {

    public class BoardManager : MonoBehaviour
    {
    // Using Serializable allows us to embed a class with sub properties in the inspector.
    [Serializable]
    public class Count
    {
    public int minimum; //Minimum value for our Count class.
    public int maximum; //Maximum value for our Count class.


    //Assignment constructor.
    public Count (int min, int max)
    {
    minimum = min;
    maximum = max;
    }
    }
     
  49. Akorra-Pendragon

    Akorra-Pendragon

    Joined:
    Sep 14, 2016
    Posts:
    2
    Hey I stumbled into two separate problems that might be related:
    1. The game ocasionaly Spawns a Player(Clone), in addition to my player;
    2. I'm also spawning an OuterWall(clone) like you'd spawn a wall or an item but with the outerwall characteristics (I believe this happens every game);

    If anyone Has any Idea I'd sure apreciate it if you could help me out...
     
    Last edited: Sep 14, 2016
  50. Akorra-Pendragon

    Akorra-Pendragon

    Joined:
    Sep 14, 2016
    Posts:
    2
    I took another look and turns out I must have accidently selected player and outerwall prefabs when selecting the food items prefabs and had it all on the food items slots
     
Thread Status:
Not open for further replies.