Respawner not respawning after object is destroyed

This is my code so far, which is attached to an empty game object called spawner.

#pragma strict

var prefab : GameObject;
var spawn_position;

function spawn_cube ()
{
if(prefab == null) {
spawn_position = Vector3(41.15892,5.028044,34.75238);
prefab = Instantiate(prefab, spawn_position, Quaternion.identity);
	}
}


function Start () {
    spawn_cube ();
}

So what I want to know how I get counter to respawn after and empty game object.

Here my destroy counter code called hits.js

var counter : GameObject;
// Destroy everything that enters the trigger
function OnTriggerEnter (Collider ) {
	if(gameObject.tag == "Pick"){
		Destroy(counter);
	Score.score++;
	
}

}

1 Answer

1

I don’t understand the issue. Do you want to destroy game object which hits the collider of game object which has the hits.js. I f true then you must destroy colliding object like this.

function OnTriggerEnter (Collider collider) {
    if(collider.gameObject.tag == "Pick")
        Destroy(collider.gameObject);
}

The “counter” is a prefab instance. You must not destroy it. What is it for by the way?