How to destroy randomly generated objects
Objects are randomly generated in an array as shown below.
intenemyIndex=Random.Range(0,m_enemyList.Length);
varenemyObject=Instantiate(m_enemyList[enemyIndex], new Vector3(0,3,0), transform.rotation) as GameObject;
varbackground2 = GameObject.FindGameObjectWithTag("background");
enemyObject.transform.SetParent(background2.transform, false);
I would like to delete the generated object in destroy. Is there a way to destroy the randomly generated object?
c# unity3d
You can keep the generated objects in a list and discard them together later, but I thought it would be easier to self-destruct them in the enemy's script because they seem to be enemies.
// Discard when it is no longer needed in enemy scripts
Destroy(gameObject);
If it's a problem to discard it when it's no longer needed, you can discard it at a specified time.
// Discard after 1 second when no longer needed in enemy script
Destroy(gameObject, 1.0f);
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.