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

    Bilkix

    Joined:
    Dec 21, 2015
    Posts:
    5
    Hi there ! :)

    I just finished the tutorial, and it's awesome !
    but, actually...I'm getting a pretty strange bug :eek: If I run the game in the Unity Editor, everything is fine, and I can play (for a while ^^). BUT ! When I build the project on my computer (On Windows) the game starts on the second day and not the first one, and when I finish this day, it jumps to the 4th...with no food at all ! :'(

    I tried to build and run on x86 and x86_64 architecture, and the problem is still there :/ do you have any guess on that strange behavior ?
     
    EASY Studios likes this.
  2. isteveee

    isteveee

    Joined:
    Oct 31, 2014
    Posts:
    4
    I was about to post same question. In fact - there is same question at page 11 )

    Problem is not solved yet.

    Matthew, can u help us? xD

    (unity 5.3.1f1 64-bit)

    P.S. There's another fun thing: when player dies - sound of death is playing only on next "Input". Tried to make one more audio source to play only die sound, so it plays it with last enemy chop on player, and then with the next "Input". If hero dies not by enemy - sounds are fine. Starting to blaming new version of unity after all.xD
     
    Last edited: Dec 22, 2015
  3. Hedeag

    Hedeag

    Joined:
    Feb 10, 2015
    Posts:
    29
    I've made a standart game from the demo asset https://www.assetstore.unity3d.com/en/#!/content/29825
    and it work https://yadi.sk/d/hVrYDqK1mTMNB

    Maybe the problem is in modifications?
     
  4. isteveee

    isteveee

    Joined:
    Oct 31, 2014
    Posts:
    4
    Well that's strange, for i tried do the same, but my result was kinda same - 2nd day on start, next level is 4th day with no food. Uhm. I got at least one question for you, Hedeag:
    Please tell me, which version of unity do you use and it's XXbit?)
     
  5. lloydsummers

    lloydsummers

    Joined:
    May 17, 2013
    Posts:
    359
    Let me check, I did a build of it and made some changes. I might have a copy on bitbucket.

    In my case, I set it to automatically create bigger levels as you play and to include a background image to fill space. It also has some modifications for how it handles the enemies. Because the default system, once you get to 50+ enemies, will add some major delays as it animates each enemy one at a time in order and waits for the last one to complete. And finally a settings pane to allow you to restart etc... Link https://appworld.blackberry.com/webstore/content/59962984/

    The code in my local repo includes ControlFreak so I can't just grant you access to that part... but here is the repo without ControlFreak. It'll probably error because of that, but it'll let you work with the rest of the code otherwise.

    Its about 20mb: http://filearchivehaven.com/downloads/UnityProblems/Rogue.zip
     
  6. Hedeag

    Hedeag

    Joined:
    Feb 10, 2015
    Posts:
    29
    version 5.2.1 | x86
     
  7. Boris_VTR

    Boris_VTR

    Joined:
    May 19, 2015
    Posts:
    8
    I was having the same problem, so I did a little modification and game now runs ok on mobile device. If I want it to run on PC I just comment out one line of code.

    I belive the problem is in GameManager on mobile device. When GameManager is instantiated it would fire both Awake() and OnLevelWasLoaded(), so InitGame() is be called twice in a row and our game goes into all kinds of trouble. I used bool variable to check if this is first time that GameManager runs and prevents it to fire InitGame() twice.

    Idea behind this is:
    1. When script is running for the very first time, the firstInit flag is set to true. In OnLevelWasLoaded() function we check if this is first run of the script (meaning that Awake function already did call InitGame() function). If it indeed is first run, then DON'T call InitGame and set firstInit flag to false, so when game does run OnLevelWasLoaded() again, it will call InitGame() function like it should.
    2. If I want to test it on PC, I would just uncomment InitGame() call in OnLevelWasLoaded() and comment the rest of the code in same function.

    Here is current solution:

    Code (CSharp):
    1. private bool firstInit = true; // Check if script is running for the first time.
    2.  
    3. //This is called each time a scene is loaded.
    4.     void OnLevelWasLoaded(int index)
    5.     {
    6.  
    7.         // TODO: delete this, development PC only, not mobile.
    8.         //InitGame();
    9.  
    10.         if (!firstInit) {
    11.             //Call InitGame to initialize our level.
    12.             InitGame();
    13.         } else {
    14.             firstInit = false;
    15.         }
    16.     }
    Hope this solution works for you too.
     
    Last edited: Dec 26, 2015
    isteveee likes this.
  8. isteveee

    isteveee

    Joined:
    Oct 31, 2014
    Posts:
    4

    Heey, i admit that i shouldn't ask questions when i'm tired and lazy to think a bit, because answer was like.. sitting on my nose xD
    Thx for reminding that kind of approach ;) But i think u've missed "level++" on !firstinit ;)

    Code (CSharp):
    1. void OnLevelWasLoaded(int index)
    2.     {
    3.         if (!firstInit)
    4.         {
    5.             level++;
    6.             InitGame();
    7.         }
    8.         else
    9.         {
    10.             firstInit = false;
    11.         }
    12.     }
     
    Boris_VTR likes this.
  9. Boris_VTR

    Boris_VTR

    Joined:
    May 19, 2015
    Posts:
    8
    Thank you for pointing this out, I totally forgot that I changed some things. I've put level++ line at the end of InitiGame() function :)
     
    Last edited: Dec 26, 2015
  10. Bilkix

    Bilkix

    Joined:
    Dec 21, 2015
    Posts:
    5
    Thank you Boris_VTR, your solution worked fine :)
    But now it's in "play mode" that I've got troubles :p But a friend told me that my version of Unity was not stable (5.3.0) and I should use the 5.2 instead. I'll try with the 5.2 version ans keep you informed :)
     
    Boris_VTR likes this.
  11. Boris_VTR

    Boris_VTR

    Joined:
    May 19, 2015
    Posts:
    8
    What kind of troubles do you have in play mode?
     
  12. Bilkix

    Bilkix

    Joined:
    Dec 21, 2015
    Posts:
    5
    The trouble I'm getting is that I start at day 1, I finish the level, and instead of the screen with day 2 written, it's still day 1 and it does not disappear :x
    It seems I can move, but there are no walls (I think the map is not loaded for this part)
     
  13. Bilkix

    Bilkix

    Joined:
    Dec 21, 2015
    Posts:
    5
    Ok, so I installed Unity 5.2 and tried to run the game (and I removed the code that Boris_VTR gave us) and it worked nicely as it should in a beautiful world :) So I think that everyone who has the problem I had (e.g. Starting game at level2, go to 4th with no food) is due to the Unity 5.3 and I don't know why :x

    Thank all of you for your help :)
    Enjoy coding and gaming \o
     
  14. dracolytch

    dracolytch

    Joined:
    Jan 1, 2016
    Posts:
    19
    So I did just the tutorial, with no modifications, and I'm having the same issue (Day 2, no food on day 4). Works fine on PC, does NOT work fine on HTML 5 or Android. There's also too much stuff on the screen, including a monster, which shouldn't show until day 3. So... I think we're initializing on top of ourselves.

    I've just made a video demonstrating the problem:
     
    Last edited: Jan 1, 2016
  15. Bilkix

    Bilkix

    Joined:
    Dec 21, 2015
    Posts:
    5
    Hi dracolytch !

    I'm definitely not an expert on Unity, but you say in your video that you're using Unity 5.3.1. As you can see in previous replies, I got the same issue ans downgrading Unity to 5.2 fixed the problem. I didn't heard you telling you tried on Unity 5.2, so maybe it can fix your problem ? :x
     
  16. dracolytch

    dracolytch

    Joined:
    Jan 1, 2016
    Posts:
    19
    I worked on that a bit. Downloaded 5.2, but then my project didn't work. Instead of sweating it, I just moved on to other stuff in 5.2 until I hear more about what's going on with 5.3
     
  17. riccardo.monty

    riccardo.monty

    Joined:
    Apr 30, 2015
    Posts:
    1
    Hi, I tried this tutorial, on a windows 10 pc, and build to windows phone 8.1, with Unity 5.3.1 . I made all as said on tutorial, without music becouse I skipped music part. In editor all works fine, but on mobile device I found that bug "load level". After apply the flag to skip first LoadLevel event in GameManager script, all works fine on smatphone too! Only a modification is required, in compiler directive have to add: UNITY_WP_8_1 label, for windows phone 8.1 os
     
  18. Matthew-Schell

    Matthew-Schell

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

    To all having problem with this in 5.3, I'm sorry to hear that! I am going to have to take a look at the project in 5.3 and see what updates are needed to the tutorial to accommodate. There are indeed some changes to the way things work, most notably 5.3 introduces the SceneManager which will eventually replace all the scene related calls in the old API for example Application.LoadLevel.

    Thanks for the video, I just reproduced the problem on my end as well with a windows build from 5.30f4. I'll investigate and let you guys know what I figure out.
     
  19. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Heres a little cheeky hacky workaround until Matt find a cleaner solution, seems to work on PC build, just testing on a WebGL build once it compiles.
    {edit} works ok on WebGL builds too ;)

    ive just put a delay so that OnLevelWasLoaded() contents cant be run within the first 5 seconds of the game.

    Code (CSharp):
    1.     void OnLevelWasLoaded(int index)
    2.         {
    3.             // just a delay so this isnt called at the start of the game if on WebGL etc
    4.            // its a bit hacky but it works in the meantime, might have to change time if 5 secs is too high
    5.             if (Time.time > 5f)
    6.             {
    7.                 //Add one to our level number.
    8.                 level++;
    9.                 //Call InitGame to initialize our level.
    10.                 InitGame();
    11.             }
    12.         }
     
    Last edited: Jan 4, 2016
  20. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    @OboShape thanks man! I've got some messages out to the devs, will update you all when I hear back if there's a more official new workflow or if this is a bug.
     
  21. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    hey all, word from the devs is this is indeed a bug and they are investigating. Thanks for bringing it to our attention!
     
    volodymyr_webcodium and OboShape like this.
  22. varun3

    varun3

    Joined:
    Dec 19, 2014
    Posts:
    19
    I'm in the middle of step 5 and using Unity 5.3.1f1. After writing the game manager when I test the game the screen stays blue and the level doesn't show up. So I started another project and because it had everything preloaded I built and ran it but still only a blue screen showed up and stayed like that. What should I do?
     
    Last edited: Jan 16, 2016
  23. JoieL

    JoieL

    Joined:
    Jan 19, 2016
    Posts:
    3
    Hi guys, im really new in c# or js and in unity. and my english so bad.
    i wanna ask u something:
    1. what random algorithm used by unity? i interest to learn. what i get at google whole algorithm to randomize number series. but what i need is just simple like get a single random value like unity do.
    2. can i change enamy move with a* search so the enemy will chasing player? if can so how?

    im apreciate your help. im really courious!
     
  24. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    In this project we're using Random.range, you can read more about it here:

    http://docs.unity3d.com/ScriptReference/Random.Range.html

    As far as which random algorithm is being used under the hood by Unity to get random numbers I'm not sure (not sure if that was what you were asking).

    Regarding using a* you certainly could but I think in this case it might be un-necessary. The enemy does chase the player in this one using a much more simple algorithm. Here's a thread where people are discussing grid based turn based path finding, you could start here: http://gamedev.stackexchange.com/questions/30384/grid-pathfinding-with-a-lot-of-entities
     
  25. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    You're saying you imported the package in a new project, opened the completed scene and got a blue screen? I haven't seen this myself, I tested the project in 5.31 and while there is an issue (see the bug and workaround above) it did build the level and show the starting title, not a blue screen.
     
  26. JoieL

    JoieL

    Joined:
    Jan 19, 2016
    Posts:
    3
    thanks sir for your reply.
     
  27. JoieL

    JoieL

    Joined:
    Jan 19, 2016
    Posts:
    3
    hm sir i need for your aid.
    how can i get enemy spawn coordinate or vector?
     
  28. Alex_Barth

    Alex_Barth

    Joined:
    Jan 21, 2016
    Posts:
    1
    Hi, So I've hit a snag that I've been pulling my hair out at.
    What seems to be happening is that upon inputting a movement, my player seems to be able to move indefinitely without an enemy being able to respond.
    I really appreciate these tutorials, they're absolutely amazing. Thanks for any help, I'll post my scripts below.

    MovingObject
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public abstract class MovingObject : MonoBehaviour {
    5.      
    6.     public float moveTime = 0.1f;              //Time it will take object to move in seconds
    7.     public LayerMask blockingLayer;            //Layer on which collisions are checked
    8.  
    9.     private BoxCollider2D boxCollider;         //The BoxCollider2D component attached to this object
    10.     private Rigidbody2D rb2D;                    //The Rigidbody2d component attached to this object
    11.     private float inverseMoveTime;             //Used to mave movement more efficient
    12.  
    13.     protected virtual void Start()
    14.     {
    15.     boxCollider = GetComponent<BoxCollider2D> ();  //get a component reference to this objects boxcollider2d
    16.     rb2D = GetComponent<Rigidbody2D> ();           // get a reference to this object's Rigidbody 2d
    17.         inverseMoveTime = 1f / moveTime;
    18.  
    19.  
    20.     }
    21.                                                    //move returns true if it's able to move and false if not
    22.                                                     //move takes parameters for x, y directions and a raycasthit2d to check collision
    23.     protected bool Move (int xDir, int yDir, out RaycastHit2D hit)
    24.     {
    25.         Vector2 start = transform.position;          //store start position to move from, based on objects current transform.
    26.         Vector2 end = start + new Vector2(xDir, yDir); //calculate end position based on the direction parameters passed in when calling move.
    27.         boxCollider.enabled = false;                    //disable the box collider so that linecast doesn't hit this objects own collider.
    28.         hit = Physics2D.Linecast(start, end, blockingLayer); //cast a line from start point to end point checking collision on blocking layer.
    29.         boxCollider.enabled = true;                          //reenable boxCollider after linecast
    30.  
    31.         if (hit.transform == null)                          //check if anything was hit
    32.         {
    33.             StartCoroutine(SmoothMovement(end));             //if nothing was hit, start smoothmovement co-routine in vector2 end as destination
    34.             return true;                                    //return true to say that move was successful
    35.         }
    36.                 return false;                               //if something was hit, return false, move was unsuccessful
    37.          
    38.  
    39.     }
    40.  
    41.  
    42.                                                     //co-routine for moving units from one space to next, takes parameter end to specify to move
    43.     protected IEnumerator SmoothMovement(Vector3 end)
    44.     {
    45.                                                      //calculate distance to move based on square magnitude of the difference between current position and end parameter
    46.                                                      // it's cheaper
    47.         float sqrRemainingDistance = (transform.position - end).sqrMagnitude;
    48.                                                       //while that distance is greater than a very small amount (epsilon, almost zero)
    49.         while (sqrRemainingDistance > float.Epsilon)
    50.         {
    51.                                                       //find a new position proportionally closer to the end, based on movetime.
    52.             Vector3 newPosition = Vector3.MoveTowards(rb2D.position, end, inverseMoveTime * Time.deltaTime);
    53.             rb2D.MovePosition(newPosition);             //call moveposition to attached rigidbody and move it to the calculated psoition
    54.             sqrRemainingDistance = (transform.position - end).sqrMagnitude;
    55.             yield return null;
    56.  
    57.         }
    58.     }
    59.     //virtual keyword means attempt move can be overridden by inheriting classes using the override keywords
    60.     //attempt move takes a generic [parameter T to specify the type of component we expect our unit to interact with if blocked (player for enemies, wall for player)
    61.     protected virtual void AttemptMove <T> (int xDir, int yDir)
    62.         where T : Component
    63.     {
    64.         RaycastHit2D hit;                                //hit will store whatever our linecast hits when Move is called
    65.  
    66.         bool canMove = Move (xDir, yDir, out hit);        //set canMove to true if move was successful, false if failed.
    67.  
    68.         if (hit.transform == null)                       //check if nothing was hit by linecast.
    69.             return;                                      //if nothing was hit, return and don't execute further code.
    70.         T hitComponent = hit.transform.GetComponent<T>(); // get a component reference to the component of type T attached to the object that was hit.
    71.  
    72.         if (!canMove && hitComponent != null)              //If canMove is false and hit component is not equal to null, meaning moving object is blocked and as hit something it can interact with.
    73.  
    74.             OnCantMove(hitComponent);                       //call the oncantmove function and pass it hitcomponent as parameter.
    75.  
    76.     }  
    77.      protected abstract void OnCantMove <T> (T component)
    78.         where T : Component;
    79. }
    80.  
    gamemanager

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

    ajching

    Joined:
    Jan 22, 2016
    Posts:
    1
    My scene appears to display everything ok when I start the game but I can't seem to move the player at all. Any ideas on where I screwed up?
     
  30. bigcatiswatchingyou

    bigcatiswatchingyou

    Joined:
    Jan 23, 2016
    Posts:
    3
    I encountered the same problem with skipped levels and no food on android because OnLevelWasLoaded is called several times on android

    I made a workaround. by moving Restart from player to gamemanager made player.cs calls gamemanager restart

    I moved level++ from OnLevelWasLoaded to restart function in gamemanager

    and added a new line to OnLevelWasLoaded
    if (level==1)return;

    so that the game doesn't initgame twice on android

    I also added a new line to OnTriggerEnter2D in player.cs

    if (!enabled) return;

    I'm not sure if this is needed, but I added to avoid multiple triggers to exit.
     
  31. SilentFootsteps

    SilentFootsteps

    Joined:
    Aug 10, 2013
    Posts:
    1
    New error:
    ArgumentException: The thing you want to instantiate is null.
    UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:102)
    UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:79)
    Completed.BoardManager.LayoutObjectAtRandom (UnityEngine.GameObject[] tileArray, Int32 minimum, Int32 maximum) (at Assets/Completed/Scripts/BoardManager.cs:126)
    Completed.BoardManager.SetupScene (Int32 level) (at Assets/Completed/Scripts/BoardManager.cs:150)
    Completed.GameManager.InitGame () (at Assets/Completed/Scripts/GameManager.cs:90)
    Completed.GameManager.OnLevelWasLoaded (Int32 index) (at Assets/Completed/Scripts/GameManager.cs:62)

    Points to :
    Line 126 of Board Manager
    //Instantiate tileChoice at the position returned by RandomPosition with no change in rotation
    Instantiate(tileChoice, randomPosition, Quaternion.identity);
     
  32. robert4452

    robert4452

    Joined:
    Jan 25, 2016
    Posts:
    3
    I'm on the "Writing the Game Manager" part of the tutorial, and when I go to put the board and game manger into the empty object renamed GameManager, it says I need to "fix compile errors before creating new script components". I go into the BoardManager script and debug and it tells me that there is an expected ";" after:
    using Random = UnityEngine.Random
    but when I fix that error, more errors and warnings pop up. What can I do to fix this?
     
  33. Diamond_Dynamo

    Diamond_Dynamo

    Joined:
    Jan 26, 2016
    Posts:
    1
    Hi, I'm having an issue that as far as I can tell, no one else has had, but I'm having, even when I run it with scripts from Completed. I've done everything but the "Architecture and Polish" section, but when I click play, I can move the player character 1 tile in any direction (including detecting that it can't go into the outer walls), but then it doesn't accept any more input. I'm consistently getting two errors:

    StackOverflowException
    UnityEngine.Component.GetComponent[Animator]
    which is from Enemy.Start() (at Assets/Scripts/Enemy)

    I don't know why it's doing that (since identical code isn't causing it in my player script), but as far as I can tell, it's not contributing to my game-break issue.

    NullReferenceException: Object reference not set to an instance of an object
    As far as I can tell, this is on the line
    Code (CSharp):
    1. hit = Physics2D.Linecast (start, end, blockingLayer)
    in my MovingObject code.

    This error only appears after I have moved once, so I assume it's the reason I can't move again. I've seen people have issues with Null Reference Exceptions before, but that always seemed to be because they needed to assign a public variable, but forgot. As far as I can tell, that's not applicable here, and I can't for the life of me figure out what the problem actually is.

    (Side note: ever since I tried using the Completed code, my Player and Enemy scripts won't recognize MovingObject unless I add
    Code (CSharp):
    1. using UnityEditor.VersionControl;
    2. using Completed;
    to the top. If anyone can help resolve that, I'd appreciate it, but it's not as necessary as the main thing.)
     
  34. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    It sounds to me like playersTurn in GameManager is not getting set back to false after the player moves. Check your AttemptMove function in Player to make sure you have this line at the end of it:

    Code (CSharp):
    1. GameManager.instance.playersTurn = false;
     
  35. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    Can you check and make sure that all of the arrays of tile prefabs are filled in BoardManager? It sounds like you're trying to instantiate a prefab that hasn't been assigned.
     
  36. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    In that case it sounds like you were missing a semicolon at the end of a line. If once you've fixed that you get another error that means there's an additional mistake in your code. Each error should show you which line has the issue when you double click on it.
     
  37. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    Regarding the side note, any time you are using scripts from Completed, all your scripts will need to be in the Completed namespace. This may be causing other issues with your project. You can't mix scripts from the Completed and default namespaces and have them interact with each other. I would check that everything shares a namespace before going any further. If that doesn't solve it, please post the entire script you believe is causing the issue, formatted using code tags for the forum.
     
  38. tarod-net

    tarod-net

    Joined:
    May 29, 2015
    Posts:
    8
    Amazing! :) Thanks!
     
  39. SevenUnited

    SevenUnited

    Joined:
    Jan 30, 2016
    Posts:
    1
    First things first: Thanks for the Tutorial, helped me much and it was fun to follow.

    I encountered a strange Bug in the Player Movement.
    I used the MovingObject and the Player Scripts in an extended Dungeon to test it, but it just didnt work as it did in the original Roguelike Project. The Player always got out of sync with the grid. I played around and did some testing and i did find out that this behavior also exists in the Roguelike project. Post #455 describes it too.

    In some cases it is possible that the enemy turn is faster than the movement of the player, what means that you can move again while playersprite is still moving to the next gridlocation.
    In other words: you are able to call the SmoothMovement Coroutine while another instance of the SmoothMovement Coroutine is active.

    You can force this behavior by change the MoveEnemies() Coroutine in the GameManager class:

    Code (CSharp):
    1.   IEnumerator MoveEnemies()
    2.   {
    3.     enemiesMoving = true;
    4.         //yield return new WaitForSeconds(turnDelay);
    5.         //if (enemies.Count == 0)
    6.         //{
    7.         //  yield return new WaitForSeconds(turnDelay);
    8.         //}
    9.  
    10.         //for (int i = 0; i < enemies.Count; i++)
    11.         //{
    12.         //  enemies[i].MoveEnemy();
    13.         //  yield return new WaitForSeconds(enemies[i].moveTime);
    14.         //}
    15.         yield return new WaitForSeconds(0);
    16.     playerTurn = true;
    17.     enemiesMoving = false;
    18.   }
    I think the best way to fix this is by add a bool to the SmoothMovement Coroutine so that it cant be called twice.
    Maybe just check in the player update if Coroutine is already running.
     
  40. spg

    spg

    Joined:
    Aug 6, 2009
    Posts:
    79
    Just a heads up that I've been working through this OnLevelWasLoaded issue, and I have a snippet of code that should work both in-editor and in-game with no need to comment code in/out as you test. Change OnLevelWasLoaded() in GameManager.cs to look like this:

    Code (CSharp):
    1. #if !UNITY_EDITOR
    2. static bool firstRun = true;
    3. #endif
    4.  
    5. private void OnLevelWasLoaded(int index)
    6. {
    7. #if !UNITY_EDITOR
    8.     if (firstRun)
    9.     {
    10.         firstRun = false;
    11.         return;
    12.     }
    13. #endif
    14.      
    15.     level++;
    16.     InitGame();
    17. }
    Here's the full GameManager.cs with the changes if that's helpful to anyone: https://github.com/spgar/Scavenger/blob/master/Assets/Scripts/GameManager.cs
     
    Last edited: Feb 1, 2016
    Gilmo likes this.
  41. Lightone

    Lightone

    Joined:
    Jan 14, 2016
    Posts:
    1
    Thanks for the tutorial, i learned a tons of thing.

    Right now i have strange problem, the line in the console show a error but i try doble click for see what is the line have the problem but dont show me anything (i use the asset store files ) and that happend random



    i change this part of code for generate variable rand size of the room

    Code (CSharp):
    1. void BoardSetup ()
    2.         {   columns = 8 + Random.Range(0,Counter);
    3.             rows = 8 + Random.Range(0,Counter);
    4.             wallCount = new Count (5, 9 + (Counter));                    
    5.             foodCount = new Count (1, 5 + (Counter));
    6.             Counter++;
    the counter is the value of the nivel

    in the setup scene add a only parts of code (make the player appear in the exit) (for test the level xD) and the value of enemy

    Code (CSharp):
    1.  
    2. int enemyCount=2+Random.Range(0,Counter);
    3.  
    4.  
    5. GameObject.FindGameObjectWithTag ("Player").transform.position = new Vector3 (columns- 1, rows - 1, 0f);
    6.  
    and attach the camera to the player (se the room with the move of the player)

    the rest of the code is intact

    Thanks for all

    //i found the problem :)
     
    Last edited: Feb 2, 2016
  42. harkensaw

    harkensaw

    Joined:
    Feb 1, 2016
    Posts:
    1
    ok so i got up to the scripting in part 4 and hit a road block as it didn't seem to recognize the script from the video. is this a version issue? I'm running 5.3 if it is, is there anywhere with amended code for the latest unity? ive even tried copying exact script from video and its not working on either boardmanger or gamemanager. they are attached to the gamemanger gameobject. any help would be grand.
    cheers ;)
     
  43. ClinnyJones

    ClinnyJones

    Joined:
    Feb 1, 2016
    Posts:
    1
    Hello everyone. First off, big thanks for this tutorial. Plenty to learn from but I've got a small problem that is really bugging me. I'm using Unity 5.3.1f1 Personal and I've done all the tuts except the last one as I don't have the touch device. Anyways, I run my game and everything is fine except when I press anyone of the arrow keys to move my player, it automatically triggers the end of game screen with the whole, 'After 1 days , you starved text.'
    I had run through the first 8 tutorials videos with no problems but somewhere up to the end, something went wrong.
    Any advice regarding which code to look at specifically or that I can need to screen cap for help?
    Also, how would implement the changes to regarding replacing the old API code regarding LoadLevel etc with the new SceneManager one?
    Thanks!
     
  44. spg

    spg

    Joined:
    Aug 6, 2009
    Posts:
    79
    Instead of this:
    Code (CSharp):
    1. Application.LoadLevel(Application.loadedLevel);
    You want this:
    Code (CSharp):
    1. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
     
  45. coki27

    coki27

    Joined:
    Jun 17, 2015
    Posts:
    6
    Thank you Matthew for the great tutorial, keep coming back to it and I always learn something new I think it's full of great solutions. I am currently making a grid movement over time game(kinda like 2DRL but with taps instead of swipes), and I would like to know how would you go about making it so that the player input can be "cached", for example if you swipe left to right and then right to left, player would move left one step without interruption and then execute the move right action. I am currently using coroutines for movement, am i on the right track ? Maybe I should move it to the update ? Thanks again !
     
  46. tarod-net

    tarod-net

    Joined:
    May 29, 2015
    Posts:
    8
    Good point! Thanks! :)
     
  47. thesleeve

    thesleeve

    Joined:
    Sep 10, 2010
    Posts:
    16
    Thanks very much for the tutorial. I learned a lot by going through it. I'm also running into the same bug discussed above related to the Scene Manager when deploying to Android. Looking forward to the resolution. Thanks to the community for figuring out a workaround!
     
  48. robert4452

    robert4452

    Joined:
    Jan 25, 2016
    Posts:
    3
    Whenever I run the debugger on the player script, I get two errors:
    Error CS0122:'Completed.GameManager.playerFoodPoints' is inaccessible due to its protection level
    and
    Error CS0103: The name 'Move' does not exist in the current context. I even tried copy-pasting the code under the video but I still get those errors. What am I doing wrong?
     
  49. eljeffe418

    eljeffe418

    Joined:
    Jul 31, 2014
    Posts:
    2
    I've finished the tutorial but when I build it, the thing doesn't seem to want to work. I checked the build log and it doesn't indicate there are any errors.

    When I run the build it starts on day 2 and the mobs and items spawn on top of other things. And every time I play I just die on day 5, despite having 100+ food.

    Anyone else experienced this problem? Any ideas how to fix it? Thanks.
     
  50. deviantony

    deviantony

    Joined:
    Feb 27, 2013
    Posts:
    6
    +1, I'm currently searching to solve the same problem.
     
Thread Status:
Not open for further replies.