Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Spawning additional rooms

Discussion in 'Scripting' started by Kacpe2403, Mar 10, 2020.

  1. Kacpe2403

    Kacpe2403

    Joined:
    Mar 1, 2020
    Posts:
    8
    Hello, I`ve just finished random dungeon generator from this video
    Sadly I have some troubles with it. My rooms are spawning on top of other rooms and it keeps going infinite.
     

    Attached Files:

  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
  3. Kacpe2403

    Kacpe2403

    Joined:
    Mar 1, 2020
    Posts:
    8
    Thanks but now I have another problem.
    Instantiate(templates.closedRoom, transform.position, Quaternion.identity);
    in this line I'm spawning closedRoom but can I change it's x and y position in the same line? I just need it to be like 2 points higher.
     
  4. WallaceT_MFM

    WallaceT_MFM

    Joined:
    Sep 25, 2017
    Posts:
    394
    You can make an offset vector and add it to transform.position, something like this:
    Code (csharp):
    1. Vector3 offset = new Vector3(0, 0.2f, 0);
    2. Instantiate(templates.closedRoom, transform.position + offset, Quaternion.identity);
    Then just adjust the offset until you like how it looks.
     
  5. Kacpe2403

    Kacpe2403

    Joined:
    Mar 1, 2020
    Posts:
    8
    Thank you so much, I'm pretty new to C# and unity may I ask you how long did it take you to understand the code, becouse now I'm just watching those videos and copying code. Could you also give me tips for learning faster?
     
  6. WallaceT_MFM

    WallaceT_MFM

    Joined:
    Sep 25, 2017
    Posts:
    394
    Personally, I studied Computer Science at a university for 4 years and learned about Unity in my free time for about 3 of those years. I then worked with Unity professionally for about 7 years to date. That's a long time, but don't let that discourage you. The hardest part is the beginning, trying to learn all of the concepts you need for the project you're working on. No one stops learning either; yesterday I learned that I had been doing something the hard way for years that C# has a built-in way of handling. To learn faster, I recommend that you take some free courses on general programming in C#. If you can remember what it was like when you were first learning to read and write, learning programming is something like that. It takes practice. Try not to copy code from other people; it's tempting, but you'll hurt your own knowledge doing that. Once you understand what their code is doing and precisely how it works, then you can start copying, but for the most part try to train yourself to do things yourself.
    Some of the free web resources I recommend are:
    MIT Open Courseware: https://ocw.mit.edu/courses/electri...erpretation-of-computer-programs-spring-2005/
    Quill18's C# series: youtube.com/watch?v=eycAAKpoJxA&list=PLbghT7MmckI7JAftgv0CUdU4RLNivG6wY
    (His stuff is usually quite good, IMHO)
    Hackerrank problems: https://www.hackerrank.com/

    I have no affiliation with any of these things, I just personally like them.
     
  7. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,886
    Well if your copying code - you will never understand it.

    You need to just following some c# courses and then try working things out for yourself.

    https://learn.unity.com/course/create-with-code

    Try following that from beginning to end. By the end you should understand enough to start learning things on your own instead of copying code and not really getting any better.