Hi maybe I dont understand what you want from script to do.
Well so : (if i get it)
it dont destroy created wall because Destroy(gameObject); destroy object that script is attached to.
EDIT : Oh and if your wallType is something else then 1, update function dont destroy that object script is attached too because destroy is in IF statement and it has to be 1 to execute.
you maybe want to check this too :
// Kills the game object
Destroy (gameObject);
// Removes this script instance from the game object
Destroy (this);
// Removes the rigidbody from the game object
Destroy (rigidbody);
Ok, just so we’re all on the same page, I start with two walls that are children of a single empty gameobject. That gameobject has the above script attached. It looks like so:
Did you check that none of the wall/s you are instantiating have no script which may have a weird side effect? I am actually sure that something else in your project causes this to happen.
Another question: Why do you instantiate the wall in update and not already in start?
private var wallType : int;
var wall : Transform;
function Start () {
wallType = Random.Range(1,4);
if(wallType == 1){
Instantiate(wall, transform.position, transform.rotation);
Destroy(gameObject);
}
}
So if it is not being destroyed, you should be able to reproduce it somehow. You could place a Debug.Log before the Destroy and a Debug.Log after the destruction to check if that is really the problem.
This can certainly not happen. I actually meant it differently and confused even myself .
My actual question is, do you have more code in your actual project and show us only snippets? Is anything else happening in the Update function? Probably yes, otherwise you wouldn’t have to place the destruction there.
I fear you have to share your project or parts of it. It is pretty obvious that other scripts produce that issue. E.g. the Prefab you instantiate has that script in a child object. Or the intersecting walls are produces by another game object that has this script as well… That is way too much guessing for such a simple script.