Search Unity

Official 2D Roguelike: Q&A

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

Thread Status:
Not open for further replies.
  1. gamemaster0007

    gamemaster0007

    Joined:
    Apr 30, 2018
    Posts:
    3
    i fixed it so now I can load as many levels as I want, but they are all level one, and my food count is reset. what is wrong now
     
  2. melvinluismendoza

    melvinluismendoza

    Joined:
    Oct 31, 2016
    Posts:
    3
    Hi!

    Doing this tutorial in Unity 2018.1.2f1 and my problem is... weird.

    When I start the game, two instances of Board are created, and the game begins in Day 2 instead of Day 1. Proceeding to the exit always transports the game into Day 4 with Food being 0, which means game over.

    I tried starting the game and deleting the duplicate instance of board, and it seems to work as expected -- however, my game still began on Day 2.

    I commented out InitGame()from Awake() in GameManager and left it in OnLevelFinishedLoading (note that I am using the modified version of OnLevelWasLoaded provided in the upgrade document). While this made the game sort of work as expected, the game still began on Day 2 -- this time, without duplicates.

    A workaround that I found is to set
    Code (CSharp):
    1. private int level = 0
    instead of 1 in GameManager, and remove InitGame()from Awake(). I'm not sure how this will affect the game, but so far into the tutorial (Adding UI & Level Transitions), this workaround seems to make the game on my end behave like the game on the tutorial.

    I checked my scripts and I believe the all match the scripts provided in the tutorial. I'm confident I didn't miss anything. Any reason as to why this is happening?

    Great tutorial, by the way. Thank you for investing your time in this.
     
  3. Smokeythebud

    Smokeythebud

    Joined:
    Aug 9, 2017
    Posts:
    34
    Had the same issue, used the same fix you did in the new update for Unity something with how the scene loading works behind scenes I believe
     
  4. PapaSmoif5

    PapaSmoif5

    Joined:
    Jun 2, 2018
    Posts:
    1
    Thanks a lot for this tutorial :)

    Almost everything works as it should.

    However, I do have a problem. Each time I go to the next level, my input seems to become more and more delayed. After just a few levels it gets significantly annoying and eventually unplayable.
     
  5. DucaDiMonteSberna

    DucaDiMonteSberna

    Joined:
    Jan 18, 2018
    Posts:
    79

    Each Initgame set ups a board and fills it with enemies/walls, so vcalling 2 of them will get you stuck in "invisigle " object from the objects rendered behind.

    Another problem is that "GameManager is somehow a special basi class in unity and unity sometime still references the one in completed folders instead of yours; just rename your gamemanager to something else, references to in included
     
  6. ma53

    ma53

    Joined:
    Jun 7, 2018
    Posts:
    1
    The first level of the game works fine, but once I hit the exit tile, the game just exits and then "day 1" comes back up on my screen. It does not seem to be restarting or loading the second game. When I die, it works and says "after 1 days, you starved", but it just won't load the next day.
     
    Last edited: Jun 7, 2018
  7. Impc7R

    Impc7R

    Joined:
    Jun 8, 2018
    Posts:
    2
    What if you want to change some things. Let's say you add more enemies. How do you exclude new ones from the first levels before you reach a new level? If you had to add if level < 4, do you use RemoveAt/RemoveRange for lists?
     
  8. Smokeythebud

    Smokeythebud

    Joined:
    Aug 9, 2017
    Posts:
    34
    I would modify the function that adds the new enemies to the list only if level is > 4 or whatever
     
  9. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    372
    The items are not being instantiated in my game. What did I do wrong? I miss the outter walls and the food and the enemies.
     

    Attached Files:

  10. Incomitatum

    Incomitatum

    Joined:
    Jan 30, 2015
    Posts:
    7
    I'm on Tutorial 5
    [
    ]

    I'm running into the same issue @lukicamukica had some years ago here
    [ https://forum.unity.com/threads/2d-roguelike-q-a.297180/page-13#post-2509549 ]
    Assets/Scripts/GameManager.cs(18,21): error CS1061: Type `BoardManager' does not contain a definition for `SetupScene' and no extension method `SetupScene' of type `BoardManager' could be found. Are you missing an assembly reference?


    I've made a paste of my scripts.
    [ http://hatebin.com/qmmqapsqmq ]

    Like the commenter said to him all that time ago.

    I HAVE made a blank Object, dropped on the scripts, and filled in the fields properly, while afterwards making it a Prefab.

    Still no dice.

    Any advice you can offer is appreciated. I had a good stride, was learning, and now I've hit a wall. :/

    ===========
    EDIT
    ===========

    I see now, since I created both files like he told me to, but started coding in the wrong one, and then just changed the filenames I ran into the issue that:

    public class GameManager : MonoBehaviour
    public class BoardManager : MonoBehaviour


    were in the opposite files.
     
    Last edited: Jun 26, 2018
  11. Incomitatum

    Incomitatum

    Joined:
    Jan 30, 2015
    Posts:
    7
    Making a new post as I have a new issue. With the issue above fixed, I see the level build when I hit play, but then my I get a red Out of Memory error at the bottom of Unity, just before my PC locks up and needs a hard-reset.

    http://hatebin.com/cqyzmgmqqc

    any ideas why that might be?
     
  12. Incomitatum

    Incomitatum

    Joined:
    Jan 30, 2015
    Posts:
    7
  13. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Just a quick lookover, change line 43
    from: for (int y = 1; x < rows - 1; y++){
    to: for (int y = 1; y < rows - 1; y++){

    Anytime I see an out of memory, I suspect Loops gone Wild, and always take a look at them first
     
  14. Incomitatum

    Incomitatum

    Joined:
    Jan 30, 2015
    Posts:
    7
    Thank you. Such a silly mistake too, but now my machine doesn't lock up and force me to wait through a 5min restart.

    With this, I can at least keep going through the tutorial learning stuff.

    Blessings.
     
  15. ponasoft

    ponasoft

    Joined:
    Oct 6, 2013
    Posts:
    42
  16. vinci95s

    vinci95s

    Joined:
    Jul 16, 2018
    Posts:
    1
    Hi! Thanks for the tutorial, it really made the introduction to unity very funny! Just one question: I tried to change the sprites of the game and I don't know the Player can't move one step at a time, he takes steps different from 1 and he waks in a zig-zag manner. Any help? Thanks in advance!
     
  17. Name3211233

    Name3211233

    Joined:
    Jul 17, 2018
    Posts:
    1
    why my files do not look like in the tutorial and what is completed game? Desktop Screenshot 2018.07.18 - 03.57.59.01.png
     
  18. imedinaisaias

    imedinaisaias

    Joined:
    Jul 12, 2018
    Posts:
    1
    why

    Assets/Scripts/BoardManager.cs(33,18): error CS0246: The type or namespace name `Version3' could not be found. Are you missing an assembly reference?






    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System;
    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 = minimum;
    maximum = max;
    }
    }

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

    private Transform boardHolder;
    private List<Version3> 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 toInstanstiate = floorTiles[Random.Range(0, floorTiles.Length)];
    if (x == -1 || x == columns || y == -1 || y == rows)
    toInstanstiate = outerWall[Random.Range(0, outerWallTiles.Length)];

    GameObject instance = Instantiate(toInstanstiate, 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);
    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, 0f), Quaternion.identity);
    }
    }
     
  19. Deleted User

    Deleted User

    Guest

    I got a problem on the 4th tutorial. So when I tried to drag my two scripts to the Game Manager Object, I can't add my scripts. What should I do? Here's a picture of what happened:
    upload_2018-7-30_12-5-2.png
     
  20. Moonboss

    Moonboss

    Joined:
    May 22, 2018
    Posts:
    3
    Hi, sorry to resurrect an old thread. I'm trying to build a game very much like your RogueLike, and I'm also having trouble with the inverseMoveTime.

    EDIT: I think I get it. but I want to make sure: MoveTowards contains a start position, and an end position. The 3rd component of MoveTowards is the distance toward end that is moved within the time we've defined per the cosubroutine calls. So, really, the "distance moved" part of the MoveTowards call should NOT be confused with the "total" distance moved, since that is defined by the start pos and end pos. I think this is a nuance that I was missing...
    Do I now have it correct?
    ----------------------------------------
    My originally posted question: (perhaps now trivial, but I wanted to continue to include it)

    Vector3 newPosition = Vector3.MoveTowards(rb20.position, end, inverseMoveTime * Time.deltaTime

    I've read the docs. I've done the tutorial. I've searched and searched to try to find something that makes sense. It does not seem that the question posed above was not actually answered, because the docs do not explain what you did in your code.
    Perhaps I'm just slow.

    ISSUE: The MoveTowards vector calls for a float that is a distance. That would be the inverseMoveTime * Time.deltaTime.
    Per the tutorial, the units of inverseMoveTime are "per time", which is in a sense a speed... speed = distance per time.
    so I get the approach... but I don't get the entire approach. inverseMoveTime = 1 / 0.1...or 10.
    BUT the whole point of this RogueLike game is to move "1" unit. How do we get "10" whatevers to equate to "1" square?


    As a corollary, why is the "move time" defined in a turn-based game, other than the wait function in the GameManager?
     
    Last edited: Aug 5, 2018
  21. beardedinlair

    beardedinlair

    Joined:
    May 3, 2012
    Posts:
    4
    I've taken a lot of ideas from these posts, and also added in some of my own. I have an OSR stat system, each stat affects the strategy you need to use. Str does damage when you run into an enemy. Dex gives you more moves than the enemies, etc. I can source this, if anyone wants it. https://www.dropbox.com/s/ixsap33glb1lca7/theScavenger.zip?dl=0
     
  22. teknorapture

    teknorapture

    Joined:
    Feb 5, 2016
    Posts:
    1
    Hello!

    I was just wondering if there was a Text (as in non-video) version of the 2d Rogue-like tutorial? Either by Unity or a good one somewhere else on the net? I searched but it seems like most of the tutorials for Unity are videos, I prefer Text for many many reasons...

    Thanks!
     
    piersb likes this.
  23. linzee82

    linzee82

    Joined:
    Sep 12, 2018
    Posts:
    1
    I'm having an issue that has come up before but I cannot find an answer that works for me. I'm at the end of part 5 and I none of the floor tiles or outer wall tiles are rendering. I have food, inner walls, and enemies but that is it. I have double checked my code and the sorting layers for all of my tiles but can't seem to find out what the issue is. It seems like anything on the 'Floor' sorting layer is not showing. I have included my code and a screenshot if anyone can help. Thanks.

    BoardManager.cs:
    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections.Generic;
    4. using Random = UnityEngine.Random;
    5.  
    6. public class BoardManager : MonoBehaviour {
    7.  
    8.     [Serializable]
    9.     public class Count
    10.     {
    11.         public int minimum;
    12.         public int maximum;
    13.  
    14.         public Count(int min, int max)
    15.         {
    16.             minimum = min;
    17.             maximum = max;
    18.         }
    19.     }
    20.  
    21.     public int columns = 8;
    22.     public int rows = 8;
    23.     public Count wallCount = new Count(5, 9);
    24.     public Count foodCount = new Count(1, 5);
    25.     public GameObject exit;
    26.     public GameObject[] floorTiles;
    27.     public GameObject[] wallTiles;
    28.     public GameObject[] foodTiles;
    29.     public GameObject[] enemyTiles;
    30.     public GameObject[] outerWallTiles;
    31.  
    32.     private Transform boardHolder;
    33.     private List<Vector3> gridPositions = new List<Vector3>();
    34.  
    35.     void InitialiseList()
    36.     {
    37.         gridPositions.Clear();
    38.  
    39.         for(int x = 1; x < columns - 1; x++)
    40.         {
    41.             for(int y = 1; y < rows - 1; y++)
    42.             {
    43.                 gridPositions.Add(new Vector3(x, y, 0f));
    44.             }
    45.         }
    46.     }
    47.  
    48.     void BoardSetup()
    49.     {
    50.         boardHolder = new GameObject("Board").transform;
    51.  
    52.         for(int x = -1; x < columns + 1; x++)
    53.         {
    54.             for(int y = -1; y > rows + 1; y++)
    55.             {
    56.                 GameObject toInstantiate = floorTiles[Random.Range(0, floorTiles.Length)];
    57.  
    58.                 if(x == -1 || x == columns || y == -1 || y == rows)
    59.                     toInstantiate = outerWallTiles[Random.Range(0, outerWallTiles.Length)];
    60.  
    61.                 GameObject instance = Instantiate(toInstantiate, new Vector3(x, y, 0f), Quaternion.identity) as GameObject;
    62.  
    63.                 instance.transform.SetParent(boardHolder);
    64.             }
    65.         }
    66.     }
    67.  
    68.     Vector3 RandomPosition()
    69.     {
    70.         int randomIndex = Random.Range(0, gridPositions.Count);
    71.         Vector3 randomPosition = gridPositions[randomIndex];
    72.         gridPositions.RemoveAt(randomIndex);
    73.         return randomPosition;
    74.     }
    75.  
    76.     void LayoutObjectAtRandom(GameObject[] tileArray, int minimum, int maximum)
    77.     {
    78.         int objectCount = Random.Range(minimum, maximum + 1);
    79.         for(int i = 0; i < objectCount; i++)
    80.         {
    81.             Vector3 randomPosition = RandomPosition();
    82.             GameObject tileChoice = tileArray[Random.Range(0, tileArray.Length)];
    83.             Instantiate(tileChoice, randomPosition, Quaternion.identity);
    84.         }
    85.     }
    86.  
    87.     public void SetupScene(int level)
    88.     {
    89.         BoardSetup();
    90.         InitialiseList();
    91.  
    92.         LayoutObjectAtRandom(wallTiles, wallCount.minimum, wallCount.maximum);
    93.         LayoutObjectAtRandom(foodTiles, foodCount.minimum, foodCount.maximum);
    94.  
    95.         int enemyCount = (int)Math.Log(level, 2f);
    96.         LayoutObjectAtRandom(enemyTiles, enemyCount, enemyCount);
    97.  
    98.         Instantiate(exit, new Vector3(columns - 1, rows - 1, 0f), Quaternion.identity);
    99.     }
    100. }
    101.  
    GameManager.cs:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class GameManager : MonoBehaviour {
    6.  
    7.     public BoardManager boardScript;
    8.  
    9.     private int level = 3;
    10.  
    11.     // Use this for initialization
    12.     void Awake () {
    13.         boardScript = GetComponent<BoardManager>();
    14.         InitGame();
    15.     }
    16.  
    17.     void InitGame()
    18.     {
    19.         boardScript.SetupScene(level);
    20.     }
    21.    
    22.     // Update is called once per frame
    23.     void Update () {
    24.        
    25.     }
    26. }
    27.  
     

    Attached Files:

  24. Kyur0

    Kyur0

    Joined:
    Sep 23, 2018
    Posts:
    1
    Hi!

    I'm having a bit of trouble with the Enemy script. Unity says that the 'Player' namespace can't be found, however I wrote the same code as in the video. I'm using Unity 2017.3.0f3

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Enemy : MovingObject {
    6.  
    7.     public int playerDamage;
    8.  
    9.     private Animator animator;
    10.     private Transform target;
    11.     private bool skipMove;
    12.  
    13.     protected override void Start ()
    14.     {
    15.         animator = GetComponent<Animator>();
    16.         target = GameObject.FindGameObjectWithTag("Player").transform;
    17.         base.Start();  
    18.     }
    19.  
    20.     protected override void AttemptMove <T>(int xDir, int yDir)
    21.     {
    22.         if(skipMove)
    23.         {
    24.             skipMove = false;
    25.             return;
    26.         }
    27.         base.AttemptMove<T>(xDir, yDir);
    28.         skipMove = true;
    29.     }
    30.     public void MoveEnemy()
    31.     {
    32.         int xDir = 0;
    33.         int yDir = 0;
    34.  
    35.         if(Mathf.Abs(target.position.x-transform.position.x)<float.Epsilon)
    36.         {
    37.             yDir = target.position.y > transform.position.y ? 1 : -1;
    38.         }
    39.         else
    40.         {
    41.             xDir = target.position.x > transform.position.x ? 1 : -1;
    42.         }
    43.         AttemptMove <Player> (xDir, yDir);
    44.     }
    45.     protected override void OnCantMove <T> (T component)
    46.     {
    47.         Player hitPlayer = component as Player;
    48.         hitPlayer.LoseFood(playerDamage);
    49.     }
    50. }
    51.  
    Here are the errors which Unity shows me:
    Assets/Self-made_Game/Scripts/Enemy.cs(43,22): error CS0246: The type or namespace name `Player' could not be found. Are you missing `Completed' using directive?
    Assets/Self-made_Game/Scripts/Enemy.cs(43,9): error CS0584: Internal compiler error: Object reference not set to an instance of an object
    Assets/Self-made_Game/Scripts/Enemy.cs(43,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
    Assets/Self-made_Game/Scripts/Enemy.cs(47,9): error CS0246: The type or namespace name `Player' could not be found. Are you missing `Completed' using directive?
    Assets/Self-made_Game/Scripts/Enemy.cs(48,9): error CS0841: A local variable `hitPlayer' cannot be used before it is declared
     
  25. paulatkins88

    paulatkins88

    Joined:
    Oct 2, 2018
    Posts:
    3
    Please help!

    Player only moves 1 square. sound still works when pressing right or up only so the scripts are still working in the background, I have gone through the code a thousand times, I know it has something to do with MoveEnemies() not being called to change the state of playersTurn.
    I have googled for hours , this seems to be a common problem. Yes i have finished the tutorial the entire way through twice and the player sprite still only moves 1 square.
    // in GameManager.cs
    void Update ()
    {
    if (playersTurn || enemiesMoving || doingSetup)
    return;
    Debug.Log(System.String.Format("playersTurn={0} enemiesMoving={1} doingSetup={2}",playersTurn, enemiesMoving, doingSetup));
    StartCoroutine(MoveEnemies());
    }


    Debug.Log returns = playersTurn=False enemiesMoving=False doingSetup=False
    on every key press...
    Anyone know why?
     
  26. False_Baconator

    False_Baconator

    Joined:
    Oct 2, 2018
    Posts:
    35
    Hey I'm on the 11th video "enemy animator controller" and I'm having problems. the player will move once before an error occurs, saying

    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    System.Collections.Generic.List`1[Enemy].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
    GameManager+<MoveEnemies>c__Iterator0.MoveNext () (at Assets/scripts/GameManager.cs:66)
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

    In short, I think it says that the enemy that the code is trying to move inst in the list (might be wrong on that one)
    I double checked all my files but there weren't any typos or anything (that i saw). I followed everything step by step. Here's the code for the gamemanager script.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class GameManager : MonoBehaviour {
    6.  
    7.    
    8.     public float turnDelay = .1f;
    9.     public int playerFoodPoints = 100;
    10.     public static GameManager instance = null;
    11.     [HideInInspector] public bool playersTurn = true;
    12.    
    13.     private BoardManager boardScript;
    14.     private int level = 3;
    15.     private List<Enemy> enemies;
    16.     private bool enemiesMoving;
    17.  
    18.  
    19.  
    20.  
    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.  
    35.     void InitGame() {
    36.         enemies.Clear();
    37.         boardScript.SetupScene(level);
    38.     }
    39.  
    40.     public void GameOver()
    41.     {
    42.         enabled = false;
    43.     }
    44.  
    45.     // Update is called once per frame
    46.     void Update () {
    47.         if (playersTurn || enemiesMoving)
    48.             return;
    49.  
    50.         StartCoroutine(MoveEnemies());
    51.     }
    52.  
    53.     public void AddEnemyToList(Enemy script) {
    54.         enemies.Add(script);
    55.     }
    56.  
    57.     IEnumerator MoveEnemies()
    58.     {
    59.         enemiesMoving = true;
    60.         yield return new WaitForSeconds(turnDelay);
    61.         if (enemies.Count == 0)
    62.         {
    63.             yield return new WaitForSeconds(turnDelay);
    64.         }
    65.         for (int i = 0; i < enemies.Count; i++) {
    66.             enemies[1].MoveEnemy();
    67.             yield return new WaitForSeconds(enemies[i].moveTime);
    68.         }
    69.         playersTurn = true;
    70.         enemiesMoving = false;
    71.     }
    72. }
    73.  

    if you need to see the code for the other files then just ask.
     
  27. False_Baconator

    False_Baconator

    Joined:
    Oct 2, 2018
    Posts:
    35
    first you should double check the code. if there are any errors in the code (typos or the like) then it would give you that error. that's what happened to me, but i can guarantee that are situations are the same.
     
  28. GyGerr

    GyGerr

    Joined:
    Oct 6, 2018
    Posts:
    1
    This tutorial is very bad
     
  29. paulatkins88

    paulatkins88

    Joined:
    Oct 2, 2018
    Posts:
    3
    Did you ever find a solution? I am going crazy. It has to do with playersTurn for sure
     
  30. paulatkins88

    paulatkins88

    Joined:
    Oct 2, 2018
    Posts:
    3
    FOUND IT!!! i had "=" when it should be "-" for line "sqrRemainingDistance = (transform.position .......


    Code (CSharp):
    1. while(sqrRemainingDistance > float.Epsilon)
    2.             {
    3.                 //Find a new position proportionally closer to the end, based on the moveTime
    4.                 Vector3 newPostion = Vector3.MoveTowards(rb2D.position, end, inverseMoveTime * Time.deltaTime);
    5.              
    6.                 //Call MovePosition on attached Rigidbody2D and move it to the calculated position.
    7.                 rb2D.MovePosition (newPostion);
    8.              
    9.                 //Recalculate the remaining distance after moving.
    10.                 sqrRemainingDistance = (transform.position = end).sqrMagnitude;
    11.              
    12.                 //Return and loop until sqrRemainingDistance is close enough to zero to end the function
    13.                 yield return null;
    14.             }
    it should be
    Code (CSharp):
    1. while(sqrRemainingDistance > float.Epsilon)
    2.             {
    3.                 //Find a new position proportionally closer to the end, based on the moveTime
    4.                 Vector3 newPostion = Vector3.MoveTowards(rb2D.position, end, inverseMoveTime * Time.deltaTime);
    5.              
    6.                 //Call MovePosition on attached Rigidbody2D and move it to the calculated position.
    7.                 rb2D.MovePosition (newPostion);
    8.              
    9.                 //Recalculate the remaining distance after moving.
    10.                 sqrRemainingDistance = (transform.position - end).sqrMagnitude;
    11.              
    12.                 //Return and loop until sqrRemainingDistance is close enough to zero to end the function
    13.                 yield return null;
    14.             }
    your welcome.
     
  31. arkedrem

    arkedrem

    Joined:
    Oct 13, 2018
    Posts:
    20
    [BUG]

    Scavenger doesn't size correctly on a Samsung Galaxy 9.

    It leaves out the Outer Walls and you can't see the exit.

    Refer to the image for more details.
     

    Attached Files:

  32. godssalvation

    godssalvation

    Joined:
    Oct 16, 2018
    Posts:
    4
    Ryan,

    There is actually a very simple error in your code within the IEnumerator MoveEnemies() function. You created the for loop with int i to iterate through the array of enemies. When calling the array index for each enemy, you need to use i as it represents the index for each enemy object stored in the enemies array. You incidentally have enemies[1].MoveEnemy(); This throws an Index OoB because arrays begin at index 0, so there is no data stored in index 1 of the array yet. You need to have enemies.MoveEnemy(); So that it starts at 0 (i = 0 to start the loop) and then increments through the loop until it gets to the end of it (i < enemies.Count). Once you change 1 to i then it should work for you. I hope that helps!
     
  33. godssalvation

    godssalvation

    Joined:
    Oct 16, 2018
    Posts:
    4
    For whatever reason, every time I try to edit that post it gives some weird SPAM error. Anyways, the correction should have been enemies.MoveEnemy(); to replace enemies[1].MoveEnemy();

    enemies*

    you can't type enemies i ???

    that i goes in [ ] after enemies.... so strange
     
  34. godssalvation

    godssalvation

    Joined:
    Oct 16, 2018
    Posts:
    4
    Unfortunately I just joined this forum and so this answer will likely not benefit the poster due to how old it is, but maybe it will help someone else that encounters a similar issue. The problem has to do with your IF condition not having bounded braces for the entire condition. You have:

    private void CheckIfGameOver()
    {
    if (food <= 0)
    SoundManager.instance.PlaySingle (gameOverSound);
    SoundManager.instance.musicSource.Stop ();
    GameManager.instance.GameOver();

    }

    This only applies the top condition to the very first statement of playing the gameOverSound. So, when you game over, if you listen carefully, then you will not hear the game over sound because food is not less than 0 when you move (it loses one and become 99). However, the other 2 statements will run regardless of the food condition, causing your music to stop and you to enter the game over text screen each time. All you have to do is place bounding braces around the IF conditional so that it applies to all 3 statements as follows:

    private void CheckIfGameOver()
    {
    if (food <= 0)
    {
    SoundManager.instance.PlaySingle (gameOverSound);
    SoundManager.instance.musicSource.Stop ();
    GameManager.instance.GameOver();
    }
    }
     
  35. godssalvation

    godssalvation

    Joined:
    Oct 16, 2018
    Posts:
    4
    This is an old post, but for anyone who might benefit from wanting to play multiple sound clips in unity, the solution is that you have to access the clips by playing them from an array index of AudioClip [] using PlayOneShot(AudioClip clip). The tutorial demonstrates how to play a single instance of an audio clip assigned to the AudioSource sfx variable (maybe the tutorial used like efx or something as the variable name I don't recall exactly). Anyways, this always overrides the clip in sfx and thus only can play one at a time. To play multiple at once use this code instead:

    public void RandomizeSfx(params AudioClip[] clips) {
    int randomIndex = Random.Range(0, clips.Length);
    float randomPitch = Random.Range(lowPitchRange, highPitchRange);
    sfx.pitch = randomPitch;
    sfx.clip = clips[randomIndex];
    sfx.PlayOneShot(sfx.clip); ----> I think this is the only line that is changed from tutorial, but not certain.
    }

    (I believe a single audio source can handle playing about 10-12 clips at once depending on the audio demand of each clip)
     
  36. False_Baconator

    False_Baconator

    Joined:
    Oct 2, 2018
    Posts:
    35
    Thank you. it still only works with 1 level but that'll probably be covered in the next video.
     
  37. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    372
    Can I PM somebody my repo of the project? I would like to know why my zombies are dancing the hoki poki c: ScavengersFail.gif
     
  38. Jaze18

    Jaze18

    Joined:
    May 18, 2018
    Posts:
    9
    Hi,

    I hope someone can point out what's wrong with my game. I'm using Unity 2018.2.11f1.

    I ran into 2 problems after completing the board manager.
    1) The board was shifted to the left when I preview the game I've already repositioned the camera as directed by the tutorial.
    2) The zombie also spawns outside the board. I'm guessing if the board wasn't shifted to the side, the zombie would be spawning properly?

    This problem also happens when I copy and paste the code from the tutorial. Some wall tiles, food tiles and the exit tile is also missing in the Game screen. If I zoom in in the Scene screen, they show up. But then you'll see the zombie is sitting on top of a wall tile that was previously invisible.

    Thanks ahead of time
    upload_2018-10-21_13-0-7.png

    upload_2018-10-21_13-1-2.png
     
    cgottberg likes this.
  39. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    372
    check the transform position of the enemy prefab.
     
  40. Jaze18

    Jaze18

    Joined:
    May 18, 2018
    Posts:
    9
    Thanks BrewNCode. You pulled me out of the frustration pit.

    I checked the positions for the camera and all the prefabs. I changed them all the x,y,z to 0 and just played with the camera coordinates until the board was centered. It ended up at x=0, y=2. Why didn't 3.5, 3.5 work as it shown in the tutorial?

    The enemy prefab was offset by 1 on one of the coordinates. But after I zero'd it, the enemy won't show up when I preview'd the game and they still spawned outside the board sometimes.

    upload_2018-10-21_17-58-34.png

    upload_2018-10-21_17-59-36.png

    The exit now shows most of time but sometimes it's still missing. For example see below.
    upload_2018-10-21_18-4-55.png

    Thanks again.
     

    Attached Files:

  41. Jaze18

    Jaze18

    Joined:
    May 18, 2018
    Posts:
    9
    update: I played with the camera z values and can get the zombie to appear if it's set to a negative value but then some walls and food items disappear. The enemies are sorted on the unit layer and their Z value is 0. If they're set at 1, they appear but that feels like cheating.

    Another weird thing is that the above only works when I alter the values when the game is running. The camera and zombie has starting Z values of 0. I set the zombie Z value to 1, change the camera Z value to -1 (zombie shows up) then I set it back to 0 and the Zombie is still there. If I change the camera Z value to 1, the zombie disappears.


    and they're still spawning outside the walls sometimes.
     
    Last edited: Oct 22, 2018
  42. rafaelcbarna

    rafaelcbarna

    Joined:
    Oct 22, 2018
    Posts:
    1
    Hello everyone,
    I've running with a problem since last week, by no means I am an expert on both Unity and Programming in general, I'm Intern on a small Game Dev.
    I have done a couple tutorials from unity, like, creating a Timberman Clone, and a 2D Plataformer. Problem is, my boss wants that this game have both keyboard and touch screen support. I tried looking around but cant find something that makes sense to me.

    What I need to do for some help with this?
     
  43. MaximumSpice

    MaximumSpice

    Joined:
    Oct 25, 2018
    Posts:
    22
    Question about BoardManager and GameManager

    https://unity3d.com/learn/tutorials...tutorial/writing-board-manager?playlist=17150
    https://unity3d.com/learn/tutorials...-tutorial/writing-game-manager?playlist=17150

    Are we meant to copy and paste the text below or follow the video and type them? because they are both different, is the text below changed and updated because of version issues? and if so, the code below each video gives problems about the namespace 'completed' already having given definitions to gamemanager and boardmanager.
     
  44. aprilpelfrey

    aprilpelfrey

    Joined:
    Nov 13, 2018
    Posts:
    1
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class MovingObject : MonoBehaviour
    {
    public float moveTime = 0.1f;
    public LayerMask blockingLayer;
    private BoxCollider2D boxCollider;
    private Rigidbody2D rb2D;
    private float inverseMoveTime;

    protected virtual void Start ()
    {
    boxCollider = GetComponent<BoxCollider2D>();
    rb2D = GetComponent<Rigidbody2D>();
    inverseMoveTime = 1f / moveTime;
    }

    protected bool Move (int xDir, int yDir, out RaycastHit2D hit)
    {
    Vector2 start = transform.position;
    Vector2 end = start + new Vector2(xDir, yDir);
    boxCollider.enabled = false;
    hit = Physics2D.Linecast(start, end, blockingLayer);
    boxCollider.enabled = true;
    if (hit.transform == null)
    {
    StartCoroutine(SmoothMovement(end));
    return true;
    }
    return false;
    }
    protected IEnumerator SmoothMovement (Vector3 end)
    {
    float sqrRemainingDistance = (transform.position - end).sqrMagnitude;
    while (sqrRemainingDistance > float.Epsilon)
    {
    Vector3 newPosition = Vector3.MoveTowards(rb2D.position, end, inverseMoveTime * Time.deltaTime);
    rb2D.MovePosition(newPosition);
    sqrRemainingDistance = (transform.position - end).sqrMagnitude;
    yield return null;
    }
    }
    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>();
    if (!canMove && hitComponent != null)
    OnCantMove();
    }
    protected abstract void OnCantMove <T> (T component)
    where T : Component;
    }

    Getting this error in Unity:
    Assets/Scripts/MovingObject.cs(68,29): error CS0513: `MovingObject.OnCantMove<T>(T)' is abstract but it is declared in the non-abstract class `MovingObject'
     
  45. Jaze18

    Jaze18

    Joined:
    May 18, 2018
    Posts:
    9
    You should type it out, you'll learn better. but in terms of implementation both methods work.

    edited: You are correct in that there is a minor difference in the code below the video that prevents it from working. If you copy and paste the code below the video, I suggest you read along as you watch the video. I don't remember exactly but it was an extra bracket and a line of code that had to be removed for it to work.
     
    Last edited: Nov 19, 2018
  46. Jaze18

    Jaze18

    Joined:
    May 18, 2018
    Posts:
    9
    I figured it out. Just wanted to answer my own question in case some one else is banging their head like I was. The tile/wall/food/exit prefabs had sprites that were offset. Click the little arrow on the prefabs to open the sprite and check the offset. God knows why the sprite wasn't centered in the prefab when it was originally created. Hope this helps some other lost soul.

    In fact there was a lot of default offset issues throughout the tutorial. Still not sure why it happened.
     
    Last edited: Nov 17, 2018
  47. qnub

    qnub

    Joined:
    Nov 21, 2013
    Posts:
    2
    Not sure what i'm doing wrong but Unity hangs when i try to play scene on 5th video when GameManager is done…

    It just show rainbow disk and load CPU up to 102% Looks like i've made mistake in code (type by hands, but show no errors) or link some objects wrong… But i don't know how to debug it…

    Unity 2018.2.16f1
    macOS 10.14.1

    Many thanks for any help!
     
    cgottberg likes this.
  48. Jaze18

    Jaze18

    Joined:
    May 18, 2018
    Posts:
    9
    Your code:
    if (!canMove && hitComponent != null)
    OnCantMove();

    Should be this:
    if(!canMove && hitComponent != null)
    OnCantMove(hitComponent);
     
  49. Jaze18

    Jaze18

    Joined:
    May 18, 2018
    Posts:
    9
    I'm no expert but try checking your loops.compare it with the actual code below the video.
     
    cgottberg and qnub like this.
  50. qnub

    qnub

    Joined:
    Nov 21, 2013
    Posts:
    2
    You're right. As always it happen – i've checked it twice already. But after your post checked again and voila!



    I've copypasted first loop and forgot to change variable name…
    Thanks!
     
Thread Status:
Not open for further replies.