GUI destroy instantiated Objects

Hello,

I’ve been scouring these forums for hours, and made lots of progress, but this is really stumping me.

Basically i have a GUItexture that i want to destroy a bunch of Cubes, spawned by another GUItexture. I’m a programming noob coming from Maya, i’m getting this error;

Assets/Scripts/KillSpawned.js(21,12): BCE0023: No appropriate version of ‘UnityEngine.Object.Destroy’ for the argument list ‘(System.Type)’ was found.

from this script;

var spawn : GameObject[];
    spawn = GameObject.FindGameObjectsWithTag("Spawned");
var exceptions : GameObject[];
var recoveryTime = 10;

private var delay = 0;


function Update () {

	if (delay>0){delay -=1;}

	if (delay==0){
		if(Input.touchCount == 1){
  			var currentTouch : Touch = Input.touches[0]; 

			if(currentTouch.phase == TouchPhase.Began && guiTexture.HitTest(currentTouch.position)){
    			if (gameObject.CompareTag ("Spawned"))
    				for (var spawined in spawn)
    				{
       					Destroy(GameObject);
   					}
				}
			}
		}
	}

…any help would translate directly to extra hair on my head.

Thanks heaps.

Your problem boils down to one letter, actually-

Where you have the line

Destroy(GameObject);

it is trying to destroy the class 'GameObject'- not any particular GameObject, but the entire class. (This makes even less sense than it sounds like).

Instead, you should be using the automatic lookup function to find the attached gameObject-

Destroy(gameObject);

Or, in fact, for that specific case,

Destroy(spawined);

Now, remember that this will only work once, unless you create new objects to fill the gaps which are now left in your array.

There is one other problem, actually- you should be doing the line

spawn = GameObject.FindGameObjectsWithTag("Spawned");

inside of the Start function, not directly under the variable declaration.

Hey Mate, thanks for the reply,

Firstly to explain my scene more clearly, there is a script attached to the GUITexture which instantiates 10 instances of a Cube prefab when touched. This second button is meant to kill them all at once, hopefully…

I’ve made the suggested amendments, and the error message has left, yea, but i’m still not experiencing the poly death i was hoping for. This is with,

Destroy(gameObject);

when i use,

Destroy(spawn);

i get this error

Assets/Scripts/KillSpawned.js(23,12): BCE0023: No appropriate version of ‘UnityEngine.Object.Destroy’ for the argument list ‘(UnityEngine.GameObject)’ was found.

I threw in a quick print “kill” to make sure things are above board on that side, and all seems well.

any further ideas?

Cheers.