void FixedUpdate() { float volume = mRecordSound.GetVolume(); if (volume > 0.5f && !mbStartGame) { this.StartGame(); } else if (mbStartGame) { mStartGameTime += Time.fixedDeltaTime; mVolumeSilder.value = volume; float wallgroupspeed = float.Parse(mBirdXSpeed.text); float walldistance = Time.fixedDeltaTime * wallgroupspeed; //Debug.Log(volume); // if (volume > 0.4) float yforce = float.Parse(mBirdYForce.text); mMainPlayerRigidbody.AddForce(new Vector2(0, volume * yforce)); for (int n = 0; n < mListWall.Count; n++) { GroupWall curWall = (GroupWall)mListWall[n]; curWall.Update(walldistance); } // 检查最后一个来确定是否需要添加新的wall if (mListWall.Count > 0) { GroupWall backWall = (GroupWall)mListWall [mListWall.Count - 1]; float localx = backWall.GetXPos(); if (localx < 400) { NewGroupWall(); } } // 删除过线的wall deleteDeadWall(); // if (mMainPlayer.anchoredPosition3D.y < -680 || mMainPlayer.anchoredPosition3D.y > 620) { StopGame(); } } }
void deleteDeadWall() { mdeadWall.Clear(); for (int n = 0; n < mListWall.Count; n++) { GroupWall curwall = (GroupWall)mListWall[n]; if (curwall.GetXPos() < -40) { mdeadWall.Add(curwall); } } for (int m = 0; m < mdeadWall.Count; m++) { mListWall.Remove(mdeadWall[m]); GroupWall curwall = (GroupWall)mdeadWall[m]; Destroy(curwall.mWallGroup); } }