public void NewGroupWall() { GameObject newWallGroup = (GameObject)Instantiate(mWallGroupSource, mWallGroupSource.transform.position, mWallGroupSource.transform.rotation); newWallGroup.transform.SetParent(this.transform); GroupWall newGroup = new GroupWall(newWallGroup, this); mListWall.Add(newGroup); }
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); } }
public void StartGame() { mbStartGame = true; mStartGameTime = 0; // 删除老的wall for (int n = 0; n < mListWall.Count; n++) { GroupWall curwall = (GroupWall)mListWall[n]; Destroy(curwall.mWallGroup); } mListWall.Clear(); // 还原主角y位置 mMainPlayerRigidbody.isKinematic = false; Vector3 vpos = mMainPlayer.anchoredPosition3D; vpos.x = mPlayInitPosX; vpos.y = mPlayInitPosY; mMainPlayer.anchoredPosition3D = vpos; this.NewGroupWall(); mTips.SetActive(false); mStartGameSound.Play(); }