Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

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

    Jaze18

    Joined:
    May 18, 2018
    Posts:
    9
    Good to hear you found your problem. Out of memory problems in simple programs often has to do with loops running wild.

    I just completed the "Enemy Animator Controller" section and the game won't load the board. It did before. When I remove "enemies.Clear()" in the gameManager.cs, the board loads. But either way the game freezes after I move once. and this error is displayed on the Console:

    NullReferenceException: Object reference not set to an instance of an object
    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)


    also can't seem to get the following line of code to work:
    SceneManager.LoadScene (0);

    it produces an error. So I'm using the obsolete version:
    Application.LoadLevel(Application.loadedLevel);
     
    Last edited: Nov 19, 2018
  2. Jaze18

    Jaze18

    Joined:
    May 18, 2018
    Posts:
    9
    was missing this line of code that initiated the List:
    enemies = new List<Enemy>();

    still not sure about second problem
     
  3. Lockes_TheThief

    Lockes_TheThief

    Joined:
    Apr 28, 2014
    Posts:
    17
    I'm having an error. Right after I finished the Enemy script the game is not putting the player or the enemies on the screen. Everything else (walls, food, etc) load fine.
     
  4. Lockes_TheThief

    Lockes_TheThief

    Joined:
    Apr 28, 2014
    Posts:
    17
    There is a warning when I take a semi colon out to test that says the hit variable is decalred but never used in the Player class.
     
  5. MaximumSpice

    MaximumSpice

    Joined:
    Oct 25, 2018
    Posts:
    22

    Yep thank you, that was in my first week or using Unity. I have been doing "Space Shooter" following along doing it all by hand. I LOVE IT! So I will go back and do rouge like later, but I had figured out what was wrong, thanks for your reply though :) I will certainly give it a better attempt later on.
     
  6. Lockes_TheThief

    Lockes_TheThief

    Joined:
    Apr 28, 2014
    Posts:
    17
    I got the script working (apparently I forgot to drag a sprite into a Gameobject in unity but my code was clean). I'm running into a new issue where I can't get the player on the screen unless I put him in the hierarchy. Even if I do I can't get him to move. Has anyone ran into this issue or might have a solution for it?
     
  7. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    109
    Hi everyone. Im working through this tutorial, I have got to the part where it tells me to add my Component (Walls.cs) to all the 8 Wall prefabs. (2:09 in the video here: https://unity3d.com/learn/tutorials...al/creating-destructible-walls?playlist=17150 . It says I can highlight all of the Wall prefabs, and click 'Component' at the top, and add Wall. But All my scripts in that dropdown are greyed out. (They are also still greyed out when only one Wall prefab is selected.)

    Im using the new Unity 2018.3.0f2 , is this why? (Of course, I realise the workaround for just manually adding the script to the 8 each separately in the Prefab edit mode.

    If anyone can tell me it should work doing it the way in the video, and how come mine is greyed out, that woud be great. Thanks
     
    jubellini and jezzaboy like this.
  8. MaximumSpice

    MaximumSpice

    Joined:
    Oct 25, 2018
    Posts:
    22
    Just some feedback for these tutorials which I know a lot has been left, but I feel like I still should.

    I have done every unity tutorial up to this one, been loving them. I am science/maths trained and teach high school maths, plus have been a gamer/computer nerd my whole life. But I will say I am new to coding.

    That being said, this tutorial is by far THE worst one. Yes it is aimed at a higher level, but honestly, using Unity is not hard, the difficulty IS the coding. Unity is like photoshop or blender, it takes time learning how the program works and what you can do in it, but honestly, its not hard. The hard part of this tutorial and all of these tutorials is actually typing your code out once you know how to use unity and what each button does, etc.

    These tutorials SHOULD be aimed at coding and teaching different types of coding. I have been reading up C# on the internet, in books, watching youtube videos, messing around my self in unity and researching using the documentation and these unity tutorials which are amazing, until this lot.

    The 2d Rougelike tutorials are a mess. They explain nothing in terms of coding but at an "intermediate" level making prefabs? making animations? none of these are hard if you have a good understanding of computing in general and have played with unity for a bit. The hard parts ARE the coding and this tutorial explains nothing, moves insanely fast and also codes VERY differently to the other tutorials (I assume this is because its a different person and hence different style of coding)

    One MAJOR thing I hated was the tutorials never do tests through coding like the other tutorials.

    That is, if we code this object, what happens, oh look we get part of what we wanted but now there is a new problem, right we need to fix this, okay fixed now what happens, ah we get the action we wanted, so now we can work on adding the next step.

    None of this trail and error method is found here which is how you ACTUALLY learn, its a slower pace and you understand the different pieces of coding. This is HOW you learn at high school AND university.

    I hope my feedback can be used to improve future tutorials, as I said I have loved them so much until this point and I intend to keep learning but please don't do another in this style.
     
    EoinTrainor11 and jeanpoolay like this.
  9. Cireva

    Cireva

    Joined:
    Jan 3, 2019
    Posts:
    2
    So I was following the tutorial along without problems, but had a big question mark after watching "2.2 Writing the Game Manager", where we add the level generation into the game.
    What I dont understand is how does unity place all the tiles correctly? In the code we only have a logical presentation of the level in form of the Gridpositions which range from (0,0) to (7,7), but how does Unity figure out that the tiles are 32px width and how to space them out correctly?
     
  10. EspritElf

    EspritElf

    Joined:
    Dec 30, 2018
    Posts:
    1
    The pixels per unit conversion is in the master Scavenger sprite sheet - 32 pixels per unit. You can view it by opening the master sprite sheet in the inspector window.
     
    Cireva likes this.
  11. Cireva

    Cireva

    Joined:
    Jan 3, 2019
    Posts:
    2
    I see, thanks alot.
     
  12. playgamemy

    playgamemy

    Joined:
    Nov 3, 2016
    Posts:
    1
    I actually have the same question. After reading your replies I read some more and I am still confused as how things are actually rendered correctly in this tutorial. You mentioned the pixels per unit conversion is in the master sprite sheet but none of the script use the sprite sheet - it used the prefab made from the sprite sheet which carries none of that info/property?

    My main confusion is with instantiate API, the parameter is the position of the game object. How does it know if it is refering to the pixel or to the "unit" in the first place? How does it knows it should convert base on instantiating game object pixel per unit property? What if there are sprites that have different "pixels per unit", wouldn't that mess things up badly? I look at the completed project again and realise the world space is already 32 pixels per unit and therefore all are in position... but how and where can I modify it?

    I ask because when I create my game which has a 8x5 board, when I instantiate my "tile" (which is a UI element), it is instantiate with pixel as the input (!?) and I have to do the math in the script to manually convert the grid position to pixel such it is at the right place.... I do not fully understand the difference and why these behave differently!
     
    Last edited: Jan 11, 2019
  13. Chachapoya

    Chachapoya

    Joined:
    Jan 14, 2019
    Posts:
    5
    Same question than playgamemy . this parameter must be store somewhere else than the master sheet ?
    When I remove all the original sprite its still stuck on 32px.
     
  14. Davlin

    Davlin

    Joined:
    Feb 19, 2013
    Posts:
    55
    Hello

    Any idea how to restart the game without quitting from it? I just want to add "Start again" button in the "Death screen".
     
  15. jezzaboy

    jezzaboy

    Joined:
    Jan 25, 2019
    Posts:
    1
    I have this problem as well
     
  16. ronarscorruption

    ronarscorruption

    Joined:
    Feb 6, 2019
    Posts:
    1
    I know this is an old post, but, for anyone looking for a solution...

    I had the same problem - food would tick down one per frame and the player would move in a random-seeming zigzag manner. But only on level 1 - as soon as there were enemies, movement suddenly... worked. It seemed like no matter what I changed the turnDelay to, there was no delay between accepting input and accepting the next input. I thought maybe there were two players loaded, or the game needed to be reset before the first level or... No, none of those things.

    I'm still not sure *why* the problem was happening, but I eventually solved it by, in GameManager MoveEnemies, I changed:
    if (enemies.Count == 0)
    to:
    if (enemies.Count < 1)

    which I guess checks for null and stuff? Anyway, the game started running normally after that. Phew!
     
  17. az_cotic

    az_cotic

    Joined:
    Feb 15, 2019
    Posts:
    1
    Hi, Unity Lovers, i have a litle problem with my Project

    First i try to follow the tutorial step by step, but in the end the Player Unit just can go to the right (not up, not down, not left), and when it does later go to the left automaticly if i left the keyboard without touch it.

    Then i think it was a mistake from the Emulator, but no, when i Build the app as Standalone same problem.

    Third, i try to test the project "Complet Project" included in the tutorial, same problem

    Fourth i try to build the project "COmplet Project", same problem.


    Is There somebody that throuing this same issue?

    NOTE: I am using the same .cs that Unity has in their Tutorial Page. Copy and Paste, and i dont have any Compile Errors.
     
  18. unity_MimD7MeOWM9u9A

    unity_MimD7MeOWM9u9A

    Joined:
    Feb 19, 2019
    Posts:
    1
    I'm on the first video, and i have no animation file, so when he says to save the playerIdle sprite in animation i have no where to save it. i don't want to save it elsewhere in case it becomes a problem later in the tutorial.
     
    DeadlyTiger468 likes this.
  19. nuhjeea

    nuhjeea

    Joined:
    Mar 26, 2014
    Posts:
    1
    I'm on 2D Roguelike tutorial (BoardManager/GameManager videos) and keep getting "no monobehaviour" error even when I add completed script to the object. It just won't let me apply the scripts to the "GameManager" object even though my class clearly inherits from MonoBehavior in the code. (says same thing for compelted code too when I try to apply script to the object)
     
  20. Deleted User

    Deleted User

    Guest

    @Matthew-Schell

    Hi!

    I'm launching myself into this tutorial, using 2018.3.6f1 (and the next versions).

    Once I've finished, I hope I'll be able to make a game of my own based on what I've learnt here. :)
     
    Last edited by a moderator: Feb 28, 2019
  21. Deleted User

    Deleted User

    Guest

    Almost finished and I have a big problem. After applying the modifications indicated in the upgrade guide that consist in using the following three functions in the GameManager script
    Code (CSharp):
    1.     private void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
    2.     {
    3.         level++;
    4.         InitGame();
    5.     }
    6.  
    7.     private void OnEnable()
    8.     {
    9.         SceneManager.sceneLoaded += OnLevelFinishedLoading;
    10.     }
    11.  
    12.     private void OnDisable()
    13.     {
    14.         SceneManager.sceneLoaded -= OnLevelFinishedLoading;
    15.     }
    instead of the deprecated
    Code (CSharp):
    1.     private void OnLevelWasLoaded(int index)
    2.     {
    3.         level++;
    4.         InitGame();
    5.     }
    the game, that was working more or less well, is now in complete shambles.

    I download the complete version in an entirely new project and tried it; it works. I guess I'll have to study that one instead of carrying on with this tutorial.
     
  22. jl3988

    jl3988

    Joined:
    Mar 1, 2019
    Posts:
    2
    In the tutorial, the script for BoardManager can be put into an asset. However, when I created a separate project and create another BoardManager script and use the exact same code, why does it give the warning "No MonoBehaviour scripts in the file, or their names do not match the file name."?
     
  23. Deleted User

    Deleted User

    Guest

    If the prefab already exists, why don't you use it? Why do you create a new one?
     
  24. jl3988

    jl3988

    Joined:
    Mar 1, 2019
    Posts:
    2
    Because I need it for a separate project. It's not a roguelike, but needs a random map generator.
     
  25. Deleted User

    Deleted User

    Guest

    Okay, I suppose from your answer that you are not using any assets from the 2D Roguelike in your project, is that it? In that case, it might be just a glitch. Quit Unity and Visual Studio and restart them.
     
    Last edited by a moderator: Mar 6, 2019
  26. aseay

    aseay

    Joined:
    May 26, 2018
    Posts:
    1
    How do you restart the game from a specific level? I know you can start at a certain level, but I want to edit this in game (user clicks a button that takes them to that level). How do I 'refresh' the game to have a specific level?
     
  27. PathWithHeart

    PathWithHeart

    Joined:
    Nov 21, 2018
    Posts:
    2
    I have a question, this is tutorial, right?
    It's how people (who want to learn) learned, no shsh-coding.
    But why when I just ran your game on high performance system, it was significally slowing down from each new enemy. They got the unique fantastic AI?
    Second, I was running game (for experimental purposes) on simple quality (or worse), and bam... game control has broken, i make one movement, and character move in this direction very slowly, and don't react on other commands. But food count from additional buttons press work and decrease.
    And then people say: oh, game made by Unity, it's certainly badly optimised. But it's because developers is inexperienced and clumsy.
    But really, guys, don't you think, that you're initially teaching people how to make badly optimised games with your badly optimised tutorial.
    Or new versions of Unity (I was trying in 2017.3.1 and Unity 2019.1.0b7 on Windows 7 - with same results) have broken your tutorial? Ok, but why Unity Hub still has a link for it?
     
  28. Deleted User

    Deleted User

    Guest

    Or maybe it's just your computer? Or maybe you did something wrong, didn't follow the tutorial properly? Is your Windows up to date?

    No performance problems on my side. Windows 7 SP1 up to date. The only glitch I have with this tutorial is that some enemies tend to spawn inside walls...

    Bashing people will lead you nowhere either.
     
  29. PathWithHeart

    PathWithHeart

    Joined:
    Nov 21, 2018
    Posts:
    2
    First, I didn't follow the tutorial, I just run your existing game. (Or make build and run)
    Second, on Day 1 (without enemy on screen) it work nice (No performance problems). With one enemy it slightly slow down (hardly notice). With four enemy slow down between movement is very notable (like 2-3 times slower than without enemies).
    I got SP1 too, but how this came from Windows. Without enemy it work correct, and with it slow down. And problem is not in the logic of enemy?
    If you doubt, almost all (interest to me) existing games work on my system fine. This tutorial is not.
     
  30. CRPorter

    CRPorter

    Joined:
    Mar 18, 2019
    Posts:
    1
    Hey, quick question here. I'm following the tutorials and when they go to test the animation, it actually shows the character and animation just by clicking the play button, but I'm not able to see the character at all when I do that. Is there something else that I need to do to get the character to actually show up?
     
  31. DevinDazzlr

    DevinDazzlr

    Joined:
    Dec 3, 2013
    Posts:
    6
    In MovingObject, the AttemptMove function has this code:

    Code (CSharp):
    1. // Set canMove to true if move was succesful, false if failed
    2. bool canMove = Move(direction, out hit);
    In Player, the overridden AttemptMove function does this:

    Code (CSharp):
    1. //Call the AttemptMove method of the base class, passing in the component T (in this case Wall) and x and y direction to move.
    2. base.AttemptMove <T> (xDir, yDir);
    3.  
    4. ....
    5.  
    6. if (Move (xDir, yDir, out hit))  {
    7.     ...
    8. }
    Does this not mean that the player is moved twice each move since both the base class and Player class will do a call to Move for each AttemptMove?
     
  32. gamalalejandro98

    gamalalejandro98

    Joined:
    Oct 26, 2018
    Posts:
    2
    Hello Matt, thanks for the tutorial, Im learing a lot.

    I wanted to point out that as of version 2018.3.8f1, prefabs work a bit differently than by the time the tutorials were recorded: During the walls script video, I had to manually add the script to each prefab because the editor couldnt add it to all the walls at the same time as you did. I found in the manual that one can now create a "parent" prefab and add each derived prefab variation to it. But this only allowed me to add the script to the parent and the chillds didnt got it.

    Surely there is a way to add components to mutiple prefabs in the current version, but I couldnt find it and it would be nice to point it out in the video (I have annotations turned on just in case!).
     
  33. gamalalejandro98

    gamalalejandro98

    Joined:
    Oct 26, 2018
    Posts:
    2
    Same. Cant find a solution.
     
  34. Deleted User

    Deleted User

    Guest

    Just built and ran the game up to day 6; no slowing down for me...
     
  35. bambamm22

    bambamm22

    Joined:
    Mar 28, 2019
    Posts:
    1
    ต้องการรวยต้องการมีเงินใช้ ต้องการเป็นเศรษฐีต้องเข้ามาเล่นหวยออนไลน์ที่เว็บนี้แค่นั้น




    หวยออนไลน์
     
  36. unity_zdVlRpVUQkNDbA

    unity_zdVlRpVUQkNDbA

    Joined:
    Apr 7, 2019
    Posts:
    1
  37. OldschoolProgrammierer

    OldschoolProgrammierer

    Joined:
    Mar 11, 2018
    Posts:
    1
    Hello, I have a beginners question about the Instantion of prefabs and GameObjects in the 2d roguelike project. I wonder why every instantiated objects/prefab gets aligned in a grid and how this can be costumized.

    Example:

    Instantiate (floorTile_1, new Vector3 (1, row, 0f), Quaternion.identity);
    Instantiate (floorTile_2, new Vector3 (2, row, 0f), Quaternion.identity);

    floorTile_2 gets rendered next to floorTile_1 on the right side. Why does one unit in the vector mean one "grid space"? I would somehow expect unity to render the floorTile_2 on top of floorTile_1 with only one pixel offset to the right.

    Another example:

    GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
    cube.transform.position = new Vector3(4, 4, 0);

    Unity renders the cube close to the center of the board in the 4x4 grid cell. Where can I define this behavior? How could I adjust the grid and the size of one "cell"? Would it be possible to render object pixelwise?

    Some help or hints would be much appreciated, thank you.
     
    Last edited: Apr 11, 2019
  38. jleven22

    jleven22

    Joined:
    Mar 26, 2019
    Posts:
    436
    Hey all, I'm getting an error on the Board Manager script per the line:

    if (x == -1 || x == columns || y == -1 || y = rows)

    "Operator '||' cannot be applied to operands of type 'bool' and 'int'


    I'm really fresh to C sharp so can someone help explain what I'm doing wrong? I've written the code exactly as dictated.

    Thanks!
     
  39. Deleted User

    Deleted User

    Guest

    You need to pay attention when you write a script. Why do you put only one = in || y = rows)?

    The line in the tutorial reads:

    Code (CSharp):
    1. if (x == -1 || x == columns || y == -1 || y == rows)
     
  40. jleven22

    jleven22

    Joined:
    Mar 26, 2019
    Posts:
    436
    I'm an idiot, forgot "==" before rows.
     
  41. jleven22

    jleven22

    Joined:
    Mar 26, 2019
    Posts:
    436
    I am getting the following error message:

    "Assets\Scripts\MovingObject.cs(23,20): error CS0161: 'MovingObject.Move(int, int, out RaycastHit2D)': not all code paths return a value"

    ____________________


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public abstract class MovingObject : MonoBehaviour
    6. {
    7.  
    8.     public float moveTime = 0.1f;
    9.         public LayerMask blockingLayer;
    10.  
    11.     private BoxCollider2D boxCollider;
    12.     private Rigidbody2D rb2D;
    13.     private float inverseMoveTime;
    14.  
    15.     // Start is called before the first frame update
    16.     protected virtual void Start()
    17.     {
    18.         boxCollider = GetComponent<BoxCollider2D>();
    19.         rb2D = GetComponent<Rigidbody2D>();
    20.         inverseMoveTime = 1f / moveTime;
    21.     }
    22.  
    23.     protected bool Move (int xDir,int yDir, out RaycastHit2D hit)
    24.     {
    25.         Vector2 start = transform.position;
    26.         Vector2 end = start + new Vector2(xDir, yDir);
    27.  
    28.         boxCollider.enabled = false;
    29.         hit = Physics2D.Linecast(start, end, blockingLayer);
    30.         boxCollider.enabled = true;
    31.  
    32.         if (hit.transform == null)
    33.         {
    34.             StartCoroutine(SmoothMovement(end));
    35.             return true;
    36.         }
    37.     }
    38.  
    39.     protected IEnumerator SmoothMovement (Vector3 end)
    40.     {
    41.         float sqrRemainingDistance = (transform.position - end).sqrMagnitude;
    42.  
    43.         while (sqrRemainingDistance > float.Epsilon)
    44.         {
    45.             Vector3 newPosition = Vector3.MoveTowards(rb2D.position, end, inverseMoveTime * Time.deltaTime);
    46.             rb2D.MovePosition(newPosition);
    47.             sqrRemainingDistance = (transform.position - end).sqrMagnitude;
    48.             yield return null;
    49.         }
    50.     }
    51.  
    52.     protected virtual void AttemptMove <T> (int xDir, int yDir)
    53.         where T : Component
    54.     {
    55.         RaycastHit2D hit;
    56.         bool canMove = Move(xDir, yDir, out hit);
    57.  
    58.         if (hit.transform == null)
    59.             return;
    60.  
    61.         T hitComponent = hit.transform.GetComponent<T>();
    62.  
    63.         if (!canMove && hitComponent != null)
    64.             OnCantMove(hitComponent);
    65.     }
    66.  
    67.     protected abstract void OnCantMove<T>(T component)
    68.         where T : Component;
    69. }
    70.  
     
  42. jleven22

    jleven22

    Joined:
    Mar 26, 2019
    Posts:
    436
    Yes, it's often my issue. So many typos. Not a good look.

    But I just posted another question -- would you mind taking a look?
     
  43. Deleted User

    Deleted User

    Guest

    In the console, double click on the error message and see what line exactly is concerned. Then compare what you wrote with the tutorial.
     
  44. Kraily4t8

    Kraily4t8

    Joined:
    Mar 21, 2019
    Posts:
    1
    Hello, I am on the Enemy Animator Controller, however I've bumped into a strange issue of the player only being able to move horizontally. Another Issue I have is the player and enemy turns, for some reason the enemy moves multiple times before the player can. I checked the code in the moving object, GameManager, player, and enemy, and it should be exactly the same as the one in the tutorial. Has anyone else ran into a similar issue?
     
  45. lazy-fox

    lazy-fox

    Joined:
    Feb 2, 2019
    Posts:
    14
  46. Toastendo

    Toastendo

    Joined:
    Nov 20, 2018
    Posts:
    22
    hey is there a way to use the doors from this for something else....
     
  47. unity_IOfZl1OS4i5jMA

    unity_IOfZl1OS4i5jMA

    Joined:
    May 27, 2019
    Posts:
    2
    I deployed 2D rouguelike in a Android device. After showing level text, I got the only center of the board. Certainly, the board is too large to be shown in my Android device. How can I handle this problem?
     
  48. Feralfang

    Feralfang

    Joined:
    Jul 31, 2013
    Posts:
    2
    Anyone else having trouble with the level not loading after you hit the exit? My scene definitely reloads, but the board is never reinitialized.
     
  49. Feralfang

    Feralfang

    Joined:
    Jul 31, 2013
    Posts:
    2
    Turns out there was some missing code, likely because of updates to Unity not shown in the videos. I would think something this big would have been added in somehow though I suppose it could be taken as some advanced debugging.

    Code (CSharp):
    1. //This little tidbit comes after "void Awake" & before "void InitGame" in the Game_Manager script
    2.  
    3. //this is called only once, and the paramter tell it to be called only after the scene was loaded
    4.     //(otherwise, our Scene Load callback would be called the very first load, and we don't want that)
    5.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
    6.     static public void CallbackInitialization()
    7.     {
    8.         //register the callback to be called everytime the scene is loaded
    9.         SceneManager.sceneLoaded += OnSceneLoaded;
    10.     }
    11.  
    12.     //This is called each time a scene is loaded.
    13.     static private void OnSceneLoaded(Scene arg0, LoadSceneMode arg1)
    14.     {
    15.         instance.level++;
    16.         instance.InitGame();
    17.     }
     
  50. geodelamano

    geodelamano

    Joined:
    Jun 19, 2019
    Posts:
    2
    Hello, I'm stuck on video 5. I can not reproduce the image of the tutorial:

    When I want to insert my script in the GameObject GameManager I have the two messages below that appears.


    I manage to integrate them since the compenent.
    Code of Board Manager

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


    public class BM : MonoBehaviour
    {
    [Serializable]
    public class Count
    {
    public int minimum;// Valeur minimale pour notre classe Count.
    public int maximum;// Valeur maximale pour notre classe Count.

    public Count(int min, int max)
    {
    minimum = min;
    maximum = max;
    }
    public int columns = 8;
    public int rows = 8;
    public int Count wallCount = new Count(5,9);
    public int 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++) // Par rangées
    {
    gridPositions.Add(new Vector3(x, y, 0f));
    }
    }
    }
    void BoardSetup()
    {
    boardHolder = new GameObject("Board").transform;
    void Start()
    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);
    }
    }
    }

    Code of Game Manager

    using UnityEngine;
    using System.Collections;

    public class GM : MonoBehaviour
    {
    public BM boardScript;

    private int level = 3;

    void Awake()
    {
    boardScript = GetComponent<BoardManager>();
    InitGame();
    }
    void Initgame()
    {
    boardScript.SetupScene(level);
    }
    }

     
Thread Status:
Not open for further replies.