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

Load a lot of prefabs in a UnityScript

Discussion in 'Prefabs' started by Gruwe83, Sep 12, 2022.

  1. Gruwe83

    Gruwe83

    Joined:
    Jan 17, 2015
    Posts:
    3
    Hello,

    I have a problem with my "prefab management" (I would call it so). I have started to code a "Map Designer" for my game. In this designer it is possible to place quadratic tiles (2D) which are different (grass, way, water, etc. - in different versions to). You can toggle the selected kind of tile by pressing T.

    The problem now ist, that I have about 25 different tiles. My first way was that I have declared a public GameObject for each tile. So I have 25 public GameObjects in my script and i have to connect all this prefabs (each kind of tile is a prefab, tile an Box Collider, etc.)...I think there would be a better way to realise?

    Do you have a clue for me to do this better?

    Thank you!
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,456
    Can't you just have arrays?
     
  3. Gruwe83

    Gruwe83

    Joined:
    Jan 17, 2015
    Posts:
    3
    Hello,

    yes, I can have arrays. But I have just to load all prefabs in the script to put these in the array. So far as i know thats the same problem?
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,456
    You can access the array in the editor and just drag all prefabs in, or you can put them in the Resources folder and use resouce.load
     
  5. Gruwe83

    Gruwe83

    Joined:
    Jan 17, 2015
    Posts:
    3
    Oh yes, that works fine. I didn't know that! Thank you!
     
    DevDunk likes this.