how can generate an object in an empty object in unity 2D

Viewed 51

I am a 13-year-old game developer I was making a game here is an early prototype I want to generate some object in an empty object in unity 2D

1 Answers

first of all, you should give a more specific about what you mean I will try to explain as I understand what you mean and next time please give more details about your suggestion or problem

if you want to generate some object you need to make creating empty in the hierarchy section after opening any script in this empty object then you need to make a prefab about what are you planning the generate object let's give some sample

 public GameObject EnemyModel;
 public GameObject EnemyPos;
 
 void Update() {
 
     if (!EnemyPos) {
         EnemyPos= Instantiate(EnemyModel, transform.position, Quaternion.identity);
     }
 }

we are using 2 public objects first EnemyModel you should put your Enemy prefab with position after EnemyPos you need to put your main generator (empty object) that's a sample of generator/spawner

useful link about Instantiate, prefab, quaternion

[https://docs.unity3d.com/ScriptReference/30_search.html?q=Instantiate][about Instantiate]

[https://docs.unity3d.com/ScriptReference/30_search.html?q=prefab][about prefabs]

[https://docs.unity3d.com/ScriptReference/30_search.html?q=quaternion][about quaternion]

source: unity documentary

Related