I am sorry to ask a question without even a draft of a script, but…
If I have two prefabs placed roughly at the same point, so parts of them intersect, how can I always destroy object a and keep object b?
Probably I should use the collisions or something like that, but I just can’t figure out the exact algorithm.
It is not a bug, but a free generating space, so I have problems controlling what appears where, so I am trying to find/make a script to prevent these cases.
This is the script I use to spawn objects.
I just use it again, changing the z value to have +10 always.
var Xvalue:float = 0.0;
var Zvalue:float = 0.0;
var ChangeCounter:int = 1.0;
var ChangeAmount:float = 20.0;
var Technical_Couter:int = 1.0;
var PlayFieldSize:float = 0.0;
var prefab1:Transform;
function Update ()
{
if(ChangeCounter<PlayFieldSize)
{
Xvalue=(ChangeAmount*ChangeCounter);
Instantiate (prefab1, Vector3(Xvalue, 0.0, 0.0), Quaternion.identity);
if(ChangeCounter>0)
{
while(Technical_Couter<(ChangeCounter+1))
{
Zvalue=(ChangeAmount*Technical_Couter);
Instantiate (prefab1, Vector3(Xvalue, 0.0, Zvalue), Quaternion.identity);
Technical_Couter++;
}
while(Xvalue>0)
{
Xvalue=(Xvalue-ChangeAmount);
Instantiate (prefab1, Vector3(Xvalue, 0.0, Zvalue), Quaternion.identity);
}
}
ChangeCounter++;
Technical_Couter=1.0;
}
}
Also, the spawned prefab in its turn spawns one of a few prefabs at its place.
So I need to check, if the prefab at the bottom layer is too high, and collides with a prefab at the top layer, and if so, destroy the one on the top.