Hello. I want to make a function that when activated it destroys all objects with a certain tag EXCEPT a few SPECIFIC objects that are currently in the scene, can I do this? (Yes, I know the obvious answer would be to change the tag for those objects, but that would mess things up, with the way I have my scripts and references). Thanks.
Well, you have to store that they’re exceptions somehow. Stick them in a var exceptions : GameObject[ ] or give them a specific DontIncludeMe.js empty script or give the script they do have a var exclude : boolean or something.
How would I reference the array of objects I want saved in the “Destroy()” function?
Not sure, but you could add extra tag for those objects and use arrays to sort them out
You mean like this?
var exclude : GameObject[];
var destroyTag : String;
var key : KeyCode = KeyCode.Space;
function Update() {
if ( Input.GetKeyDown ( key ) ) {
for ( var ob in GameObject.FindGameObjectsWithTag( destroyTag ) ) {
var found : boolean = false;
for ( var check in exclude ) {
if ( ob == check ) { found = true; break; }
}
if ( !found ) Destroy( ob );
}
}
}