- Home /
Question by
Chootz · Aug 18, 2013 at 04:19 AM ·
javascripttriggerdestroychunks
How to destroy one of two identical triggers?
In my game I'm making a chunk generation script with trigger boxes acting as 10x10 chunks. My primary issue is that due to my setup, when I go back through an area I've already been through, then it will begin to double up on chunks. Since the two objects that are colliding are identical (including scripts), when I have the conflict trigger the destruction of the object, it will destroy both because they both run the same script and both execute the code at the same time. How can I make it so that only the first object remains when a conflict happens?
Comment
Answer by Linus · Aug 18, 2013 at 04:35 AM
static class Globals{
var removedAlready : boolean = false;
}
//Inside collision testing
if(!Globals.removedAlready){
//Do the removal
removedalready = true;
} else {
//Do not do the removal
removedAlready = false;
}
If you have many of these cubes, generate an id for the cube, make an array and assign each cube a space in the array.