我创建了这段代码,由于某种原因,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);
}
}