Z
Z
Zimaell2020-10-25 11:24:17
Unity
Zimaell, 2020-10-25 11:24:17

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

spoiler
[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;
        }
      }
    }

As a result, prefabs with a name like GiftRed (clone)(clone) are obtained.
Tell me - this is how it should be for better processing, and how to remove (clone) from the name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-10-25
@Zimaell

You can always change the name if you don't like it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question