尝试在每次创建对象时增加实例化位置 UNITY C#

trying to increment instantiate position each time object is created UNITY C#

我想知道如何设置以下代码以在每次创建对象时增加实例化位置,因此它们都彼此相邻排列。目前他们只是为了同一个位置而战,然后开始围成一圈跳舞。

public void AddUnit(string unitName, Vector3 spawnPoint, Vector3 rallyPoint, Quaternion rotation, Building creator)
    {
        rallyPoint += new Vector3(-10, 0, 0);
        Units units = GetComponentInChildren<Units>();
        spawnPoint += new Vector3(0, 0, -8);
        GameObject newUnit = (GameObject)Instantiate(ResourceManager.GetUnit(unitName), spawnPoint, rotation);
        newUnit.transform.parent = units.transform;
        Unit unitObject = newUnit.GetComponent<Unit>();

        if (unitObject)
        {

            unitObject.SetBuilding(creator);
            if (spawnPoint != rallyPoint)
            {

                unitObject.StartMove(rallyPoint);

            }
        }
    }

这个很简单。只需移动此代码

    spawnPoint += new Vector3(0, 0, -8);

在 AddUnit() 函数之外,在调用它的地方。

每次调用该函数时增加起始位置的想法。这是一个例子。

void Update()
{
    spawnPoint += new Vector3(0, 0, -8);
    AddUnit(unitName, spawnPoint, rallyPoint, rotation, creator);
}