为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
慕侠2389804 2021-06-03 22:22:38
我想知道如何设置以下代码以在每次创建对象时增加实例化位置,因此它们都彼此相邻排列。目前他们只是为了同一个地点而战,然后开始围成一圈跳舞。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);            }        }    }
查看完整描述

1 回答

?
跃然一笑

TA贡献1826条经验 获得超6个赞

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


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

到 AddUnit() 函数之外,改为调用它的地方。


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


void Update()

{

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

    AddUnit(unitName, spawnPoint, rallyPoint, rotation, creator);

}


查看完整回答
反对 回复 2021-06-05
  • 1 回答
  • 0 关注
  • 134 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信