Creating and destroying SELECTED objects and... sorting arrays??
Hello There,
I'm new in Unity. I was programming in C long time ago, two decades ago. Old, simple C. So, I have to learn everything from the beginning - mostly. Most problems I can find easily, but I have two problems I cannot understand... I'd be very gratefull if you would give me a tip.
1) First problem is creating and destroying objects in C# scripts. I can create objects, but... I have no idea how to destroy certain objects.... Call me stupid... I want to make Neural Network Simulation, so, I need to create objects inscripts and... later kill objects I don't need. However... I do not understand how to find which object is which and which to destroy separately... For instant, I'm creating 100 objects at once, using Instantiate, but then I want to destroy only objects I find worth killing... How can I do this? Destroy GameObject (x); // ????? how would I know which object is which? I do not want to kill all Objects, including background, lights, additionall objects - just the few ones I want to kill. I'm sorrry, I sound stupid, I guess... However... I'm stuck....
2) My second question is... well, question of old man using Basic and first C... ;) Is this now possible to sort arrays somehow, without checking every cell one by one?
My problem is: I will have array containing 100-1000 entities on a map. Every entity will have eyes. I could do this old school way, checking every array cell and calculate my needs, but I'd like to save my CPU ind only search entities x's and y's which are closest to me, or (old school) closest groups, or all entities in front of my entity.... Is there any way to do this faster than checking every x and y of every entity on the map?
Collision is a good idea, but only in one situation - collision ;). And.. is it faster than comparing every x and y from the array?
I'll be very gratefull for any tip... Most answers on the net I could find are rubbish or something completly different or... poor quality "tutorials" based on other "tutorials".
I know, probably there were many questions like this, but I cannot find answer for my problem or even idea where too look.... :(
Thank you and all the best! Bartosz
Your answer
![](https://koobas.hobune.stream/wayback/20220612114456im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to spawn sprites in a row randomly from a single array without double-ups 0 Answers
[HELP] Setting the parent of a transform which resides in a prefab is disabled 1 Answer
Trying to track the BoxColliders of 2 Different Sets of Instantiated GameObjects 1 Answer
[Quiz Game] How to prevent Question asked twice. HELP 1 Answer