团结因未知原因创造了太多的对象

时间:2019-02-25 19:04:58

标签: c# visual-studio unity3d

我创建了这段代码,由于某种原因,Unity无限地重复了backGround,因为对象太多,所以我无法使用调试器进行调试。 isActivated开始为false。

private void OnTriggerEnter2D(Collider2D coll)
{

    if (coll.gameObject.tag == "MainCamera" && isActivated == false)
    {
        isActivated = true;
        Rigidbody2D backgroundclone = (Rigidbody2D) Instantiate(backGround, new Vector3(46, 0, 0), Quaternion.identity);
        Rigidbody2D backgroundclone1 = (Rigidbody2D)Instantiate(backGround, new Vector3(-46, 0, 0), Quaternion.identity);
        Rigidbody2D backgroundclone2 = (Rigidbody2D)Instantiate(backGround, new Vector3(0, 21, 0), Quaternion.identity);
        Rigidbody2D backgroundclone3 = (Rigidbody2D)Instantiate(backGround, new Vector3(0, -21, 0), Quaternion.identity);
    }
}

0 个答案:

没有答案