Answer the question
In order to leave comments, you need to log in
How to get rid of (clone)?
somewhere they wrote to me that you should not constantly pull the resources for the instance, so I first got the originals from the resources and then made clones of them
[SerializeField] private Dictionary<int, Cell> Cells = new Dictionary<int, Cell>();
[SerializeField] private Dictionary<string, Cell> Prefabs = new Dictionary<string, Cell>();
[SerializeField] private string[] NamePrefabs = new string[4] { "GiftBlue", "GiftGreen", "GiftRed", "GiftYellow" };
void Start(){
GetPrefabs();
CreateBoard();
}
void GetPrefabs(){
foreach(string name in NamePrefabs){
Cell PrefabResources = Resources.Load("Prefabs/" + name, typeof(Cell)) as Cell;
Prefabs[name] = Instantiate(PrefabResources, new Vector3(-10, -10, 0), Quaternion.identity) as Cell;
}
}
void CreateBoard(){
int Num = 0;
for(int y = 0; y < 5; y++){
for(int x = 0; x < 5; x++){
Cells[Num] = Instantiate(Prefabs["GiftRed"], new Vector3(x, y, 0), Quaternion.identity) as Cell;
++Num;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question