如何检查一个树对象是否真的很接近另一个统一?

How do I check if a tree object is really close to another in unity?

我一直在用 unity 做一个生存游戏,我用下面的函数生成了树

GenerateTree 函数

void GenerateTree(int x, int y)
    {
        //define our tree

        //generate log

        int treeHeight = Random.Range(minTreeHeight, maxTreeHeight);
        for(int i = 0; i < treeHeight; i++)
        {
            PlaceTile(log, x, y + i);
        }

        //generate leaves
        PlaceTile(leaf,x,y+treeHeight);
        PlaceTile(leaf, x, y + treeHeight+1);
        PlaceTile(leaf, x, y + treeHeight+2);

        PlaceTile(leaf, x-1, y + treeHeight);
        PlaceTile(leaf, x-1, y + treeHeight+1);

        PlaceTile(leaf, x + 1, y + treeHeight);
        PlaceTile(leaf, x + 1, y + treeHeight + 1);

    }

PlaceTile 函数

 public void PlaceTile(Sprite tileSprite, int x, int y)
    {
        GameObject newTile = new GameObject();

        float chunkCoord = (Mathf.Round(x / chunkSize) * chunkSize);
        chunkCoord /= chunkSize;
        Debug.Log(chunkCoord);
        newTile.transform.parent = worldChunks[(int)chunkCoord].transform;

        newTile.AddComponent<SpriteRenderer>();
        newTile.GetComponent<SpriteRenderer>().sprite = tileSprite;
        newTile.name = tileSprite.name;
        newTile.transform.position = new Vector2(x + 0.5f, y + 0.5f);

        worldTiles.Add(newTile.transform.position - (Vector3.one * 0.5f));
    }

我认为我需要使用 if 语句来检查附近是否有另一个日志,但我需要有关如何执行此操作的帮助。

Vector2.Distance(Vector2D,Vector2D)

https://docs.unity3d.com/ScriptReference/Vector2.Distance.html

if(Vector2.Distance(Log1Location,Log2Location) > 10)
{
   //Spawn?!
}