简体   繁体   中英

Load existing GameObjects into a 2D array

I'm making a tile based board game (on a grid). In going about making the gameboard, the easy thing would be to instantiate all of the tiles in code, but then they only appear in play mode. I want to be able to edit the tiles in the editor, but I still want my tiles to be stored in a 2D array in my controller class. If I build the board in the editor, how might I go about loading them in at runtime?

Keep The Tiles in the Resources Folder Unity. At Run-time Load from the Resources and instantiate Tiles To Your Grid Positions in the Scene.

GameObject[] Tiles= (Resources.LoadAll<GameObject> ("Tiles"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM