public void Spawn(int maxe) // кол-во противников максимальное
{
while (maxe > enemes)
{
float x = Random.Range(x1, x2);
float y = Random.Range(y1, y2);
float z = 1f; // Если игра в 2d, то z = 1f;
GameObject gm = Instantiate(enemy1, new Vector3(x, y, z), Quaternion.identity) as GameObject;
gm.transform.SetParent(gameObject.transform);
enemes++;
}
enemes = 0;
}
Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption (GameObject: 'Enemes1_0(Clone)').
UnityEngine.Transform:SetParent (UnityEngine.Transform)
EnemesSpawn:Spawn (int) (at Assets/Scripts/Objects/EnemesSpawn.cs:24)
[SerializeField] private int m_maxEnemies;
[SerializeField] private GameObject m_Enemy;
private void Start()
{
SpawnEnemies(m_maxEnemies);
}
private void SpawnEnemies(int max)
{
for (int enemy = 0; enemy < max; enemy++)
{
float x = Random.Range(-8, 8);
float y = Random.Range(-5, 5);
float z = 1f;
GameObject childObject = Instantiate(m_Enemy, new Vector3(x,y,z),Quaternion.identity);
childObject.transform.SetParent(gameObject.transform);
}
}
[SerializeField] private GameObject m_Spawner;
[SerializeField] private string m_sceneName;
public void SwapScenes()
{
StartCoroutine(LoadYourAsyncScene());
}
IEnumerator LoadYourAsyncScene()
{
Scene currentScene = SceneManager.GetActiveScene();
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(m_sceneName, LoadSceneMode.Additive);
while (!asyncLoad.isDone)
{
yield return null;
}
SceneManager.MoveGameObjectToScene(m_Spawner, SceneManager.GetSceneByName(m_sceneName));
SceneManager.UnloadSceneAsync(currentScene);
}