- Home /
Question by
knowles2 · Sep 13, 2014 at 02:18 PM ·
beginnerdestroy objectcounter
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++;
}
}
Comment
Answer by Venceremos · Sep 13, 2014 at 02:34 PM
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?
Your answer
Follow this Question
Related Questions
How to add score after destroying object? 1 Answer
Counter problem 1 Answer
Unity blue screen help? (Can't add scenes) [fixed] 2 Answers
Raycast problems! 1 Answer
Beginner: For Loop freezing unity 1 Answer