void OnCollisionEnter(Collision col) { if (col.collider.tag == "Floor") { //關閉角色跳躍動作 GetComponent <_02_CowboyAnim> ().BoolJump = false; //角色站在地板上 OnFloor = true; } if (col.collider.tag == "Wall") { GetComponent <_02_CowboyAnim> ().BoolOver = true; Challenge = false; //遊戲結束 _01_GameControl.GameOverbool = true; //產生撞牆聲音 Instantiate(HitSound, transform.position, Quaternion.identity); //煙霧特效關閉 RunSmoke.GetComponent <ParticleSystem> ().enableEmission = false; } if (col.collider.tag == "Coin") { _01_GameControl.CoinNumber += 1; //刪除金幣物件 Destroy(col.gameObject); //產生金幣特效 Instantiate(CoinEffects, transform.position + new Vector3(0, 1f, 0), Quaternion.identity); //產生吃到硬幣的聲音 Instantiate(GetCoinSound, transform.position, Quaternion.identity); } }
//執行闖關挑戰 void ChallengeStart() { //開啟角色跑步動作 GetComponent <_02_CowboyAnim>().BoolRun = true; //角色往前移, 改變 z 軸 transform.Translate(0, 0, CowboyRunSpeed * Time.deltaTime); JumpMove(); LeftRight(); //如果角色沒有在對應的跑道上時 if (transform.position.x != CowboyRunWay) { CheckCowboyPosx(); } //如果角色站在地板上 if (OnFloor == true) { //煙霧特效發射 RunSmoke.GetComponent <ParticleSystem> ().enableEmission = true; } else { //煙霧特效關閉 RunSmoke.GetComponent <ParticleSystem> ().enableEmission = false; } }
float HorizontalDistance, VerticalDistance; //紀錄滑鼠移動的垂直與水平距離 // Use this for initialization void Start() { Challenge = true; transform.position = new Vector3(0, 0.25f, 0); CowboyRunWay = 0; StartReciptrocalTime = 3; //預設煙霧特效為關閉狀態 RunSmoke.GetComponent <ParticleSystem> ().enableEmission = false; }
//執行闖關挑戰 void ChallengeStart() { //角色跑步動作開啟 GetComponent <_02_CowboyAnim>().BoolRun = true; //角色往前移動, 增加 z 軸座標 transform.Translate(0, 0, CowboyRunSpeed * Time.deltaTime); ControlMouse(); if (transform.position.x != CowboyRunWay) { //移動到角色所該到的跑道 CheckCowboyPosx(); //如果角色站在地板上 if (OnFloor == true) { //煙霧特效發射 RunSmoke.GetComponent <ParticleSystem> ().enableEmission = true; } else { //煙霧特效關閉 RunSmoke.GetComponent <ParticleSystem> ().enableEmission = false; } } }