How do I find the prefab with the "Dirt" tag at the lowest coordinate?
I don't want "ores" to generate over the lowest Dirt. How can I write an if statement for that? I was thinking about something like (Mathf.Min(position)(y) if gameobject.tag =="Dirt") but I don't know yet how this things work.
So I have dirt prefabs with "Dirt" Tag and I'd like to find the lowest y position of Dirt. where the line is.
Answer by KoenigX3 · Apr 01, 2021 at 05:31 PM
In a finite amount of space, the pseudocode would be something like this:
set lowestDirt to infinite
do i = 0 to maximum_of_i
do k = maximum_of_k[i]
if tile is dirt and k < lowestDirt
set lowestDirt to k
else if tile is stone
break
end do
end do
This code would create a variable called lowestDirt, loop through all columns, then loop through the rows of each column. If it finds a dirt tile that is lower than lowestDirt, it would update the value with the new level, and keep searching for dirt tiles. The code assumes that there is no dirt under the stones in a column.
Note that this is not a working code. To create one, we would need to know how you implemented these. Also, you should really include some code when asking a question like this, because this method would not work in a procedurally generated environment.