void Awake() { bool isDestry = true; CarRoot = GameObject.Find("ShopCar"); if (CarRoot == null) { CarRoot = mGOCarPre; isDestry = false; } GameObject Obj = (GameObject)Instantiate(CarRoot.transform.GetChild(GameShop.IS.CarSel).gameObject, new Vector3(0, 0, 0), Quaternion.identity); Obj.transform.GetChild(2).transform.position = new Vector3(-0.17f, 0.05f, -.25f); Obj.transform.GetChild(2).transform.localScale = new Vector3(1.1f, 1, 1); Obj.SetActive(true); Obj.AddComponent <BoxCollider> (); Obj.GetComponent <BoxCollider> ().center = new Vector3(0, 1, 0); Obj.GetComponent <BoxCollider> ().size = new Vector3(2, 2, 5); Obj.transform.parent = transform; mGO_Light = (GameObject)Instantiate(mGOLight, new Vector3(0, 0.5f, 1f), Quaternion.identity); mGO_Light.transform.parent = Obj.transform; mGO_Light.SetActive(false); if (isDestry) { Destroy(CarRoot); } if (GameShop.IS.UPDATE != null) { maxSPD = GameShop.IS.UPDATE [GameShop.IS.CarSel, 0] * .02f + .9f + GameShop.IS.CarSel * .05f; powerBreak = (.008f + GameShop.IS.CarSel * .002f + GameShop.IS.UPDATE [GameShop.IS.CarSel, 1] * .001f); } MusicCresh = gameObject.AddComponent <AudioSource> (); MusicCresh.clip = (AudioClip)Resources.Load("sound/small_impact"); MusicCresh.volume = GameShop.IS.SoundValue; MusicHorn = gameObject.AddComponent <AudioSource> (); MusicHorn.clip = (AudioClip)Resources.Load("sound/horn"); MusicHorn.volume = GameShop.IS.SoundValue; MusicCarbreak = gameObject.AddComponent <AudioSource> (); MusicCarbreak.clip = (AudioClip)Resources.Load("sound/break"); MusicCarbreak.volume = GameShop.IS.SoundValue; MusicCarRun = gameObject.AddComponent <AudioSource> (); MusicCarRun.clip = (AudioClip)Resources.Load("sound/car_normal"); MusicCarRun.loop = true; if (GameShop.IS.isMusic) { //MusicCarRun.Play (); MusicCarRun.volume = GameShop.IS.SoundValue; } MusicRunPause = gameObject.AddComponent <AudioSource> (); MusicRunPause.clip = (AudioClip)Resources.Load("sound/car_boost"); MusicRunPause.loop = true; if (GameShop.IS.isMusic) { MusicRunPause.Play(); MusicRunPause.volume = GameShop.IS.SoundValue; } }
void Update() { if (GameUi.GameScr == GameUi.Scr.GamePauseScr) { if (MusicCarRun.isPlaying) { MusicCarRun.Pause(); } if (MusicRunPause.isPlaying) { MusicRunPause.Pause(); } return; } if (cameraspd == 0) { if (Input.GetAxis("Vertical") < 0 || isBreak) { if (spd > 0.25) { spd -= powerBreak; } if (rot.x < 3) { rot.x += .5f; } if (MusicCarRun.isPlaying) { MusicCarRun.Pause(); } if (MusicRunPause.isPlaying) { MusicRunPause.Pause(); } } else if (Input.GetAxis("Vertical") > 0 || isForword || GameShop.IS.isAuto) { if (spd < maxSPD) { spd += .002f + GameShop.IS.CarSel * .0005f; } if (rot.x > -3) { rot.x -= .5f; } if (!MusicCarRun.isPlaying && GameShop.IS.isSound) { MusicCarRun.Play(); } if (MusicRunPause.isPlaying) { MusicRunPause.Pause(); } } else { if (spd > 0.25) { spd -= .001f; } if (rot.x > 0) { rot.x -= .5f; if (rot.x < 0) { rot.x = 0; } } if (rot.x < 0) { rot.x += .5f; if (rot.x > 0) { rot.x = 0; } } if (MusicCarRun.isPlaying) { MusicCarRun.Pause(); } if (!MusicRunPause.isPlaying && GameShop.IS.isSound) { MusicRunPause.Play(); } } if (GameShop.IS.isSenser) { SenserMove(); } else { arrowMove(); } if (spd > .70) { M.mScore += .1f * spd; } } if ((transform.position.x > 6.5 && moveX > 0) || (transform.position.x < -6.5 && moveX < 0)) { moveX = 0; rot.y = 0; } float nmov = (moveX * spd) * .15f; transform.position = Vector3.Lerp(transform.position, new Vector3(transform.position.x + nmov, 0, transform.position.z + spd), Time.deltaTime * M.TimeDelt); transform.GetChild(0).GetChild(0).rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(rot.x, rot.y * .1f, rot.y * .6f), Time.deltaTime * 100); for (int i = 0; i < 4; i++) { transform.GetChild(0).GetChild(1).GetChild(i).rotation *= Quaternion.AngleAxis(10, Vector3.right); } if (cameraspd == 0) { mCamera.position = new Vector3(0, 10, transform.position.z - carPos); } else { mGOCanvas.transform.GetChild(0).GetChild(6).gameObject.SetActive(false); mCamera.position += Vector3.forward * cameraspd; if (cameraspd > 0.25 && M.gameOverCounter > 50) { cameraspd -= .001f; } // if (M.gameOverCounter < 50) { // mCamera.position += Vector3.forward * cameraspd; // } else { // spd = 0; // } if (M.gameOverCounter == 10 && GameShop.IS.mGameMode != 2) { mGOCanvas.GetComponent <GamePlayUI> ().GameOver(); if (MusicCarRun.isPlaying) { MusicCarRun.Pause(); } if (MusicRunPause.isPlaying) { MusicRunPause.Pause(); } } M.gameOverCounter++; if (M.gameOverCounter > 150 && GameShop.IS.mGameMode == 2) { resetTestDrive(); } } if (M.mDistance > 20000) { mGOCanvas.transform.GetChild(0).GetChild(6).gameObject.SetActive(cameraspd == 0); if (cameraspd == 0 && M.mDistance > 20155) { cameraspd = spd; spd = 0; } } M.SPD = spd; M.mDistance += spd; _TxtSPEED.text = (int)(spd * 100) + ""; float val = ((int)(M.mDistance / 10)) / 100f; //_TxtDIST.text = val + "" +(((int)(M.mDistance / 10))%100==0?".00":"")+(((int)(M.mDistance / 10))%10==0?"0":""); if (((int)(M.mDistance / 10)) % 100 == 0) { _TxtDIST.text = val + ".00"; } else if (((int)(M.mDistance / 10)) % 10 == 0) { _TxtDIST.text = val + "0"; } else { _TxtDIST.text = val + ""; } if (spd > 1.0) { M.MAXSPDTIME += (Time.time - diffTIme); _TxtHighSeed.transform.GetChild(0).GetComponent <Text> ().text = "" + M.MAXSPDTIME.ToString("F1"); } if (GameShop.IS.mGameMode == 1 && transform.position.x < -.7f && spd > 0.7) { M.MAXSPDTIMEOPP += (Time.time - diffTIme); } _TxtHighSeed.SetActive(spd > 1.0 && GameShop.IS.mGameMode != 2); _TxtDIST.transform.parent.gameObject.SetActive(GameShop.IS.mGameMode != 2); diffTIme = Time.time; if (blink < 100) { blink++; transform.GetChild(0).gameObject.SetActive(blink % 10 < 5 || blink > 95); } }