/* * FUNCTION: Enable controls, start player animation and movement */ public void launchGame() { StopCoroutine("playIdleAnimations"); //stop idle animations hEnemyControllerCS.launchEnemy(); if (!mecanimEnabled) //if legacy animations enabled { togglePlayerAnimation(true); aPlayer["run"].speed = Mathf.Clamp((fCurrentWalkSpeed / fStartingWalkSpeed) / 1.1f, 0.8f, 1.2f); aPlayer.Play("run"); } else //if mecanim enabled { aPlayerMecAnim.SetBool("RunAnim", true); } hSoundManagerCS.playSound(SoundManagerCS.CharacterSounds.Footsteps); //play the footsteps sound }
/* * FUNCTION: Set the menu to show in front of the HUD Camera */ public void ShowMenu(int index) { if ((int)MenuIDs.SettingsMenu == index) { //check which type of controls are active and //set the appropriate radio button if (hControllerScriptCS.isSwipeControlEnabled()) { mrSwipeControls.enabled = true; mrGyroControls.enabled = false; } else { mrSwipeControls.enabled = false; mrGyroControls.enabled = true; } //check if the music is enabled or disabled and //set the appropriate radio button if (hSoundManagerScriptCS.isMusicEnabled()) { mrMusicON.enabled = true; mrMusicOFF.enabled = false; } else { mrMusicON.enabled = false; mrMusicOFF.enabled = true; } //check if the sound is ON or OFF and se the //appropriate radio button if (hSoundManagerScriptCS.isSoundEnabled()) { mrSoundON.enabled = true; mrSoundOFF.enabled = false; } else { mrSoundON.enabled = false; mrSoundOFF.enabled = true; } } else if ((int)MenuIDs.MissionsMenu == index) //display mission menu { hMissionsControllerCS.updateMenuDescriptions(); //list the mission on the missions menu } tMenuTransforms[index].position = new Vector3(tMenuTransforms[index].position.x, 0, tMenuTransforms[index].position.z); //move the menu in front of the HUD Camera CurrentMenu = index; //set the current menu hideHUDElements(); //hide the HUD hSoundManagerScriptCS.playSound(SoundManagerCS.MenuSounds.ButtonTap); }
/* * FUNCTION: Add collected currency or activate powerup * CALLED BY: PowerupScript.Update() */ public void collectedPowerup(int index) { if (index == (int)PowerUps.Currency) //if a currency unit is collected { iCurrencyUnits += 1; //add 1 to the currency count hSoundManagerCS.playSound(SoundManagerCS.PowerupSounds.CurrencyCollection); //play collection sound hMissionsControllerCS.incrementMissionCount(MissionsControllerCS.MissionTypes.Currency); //count the collected currency for mission script //count the collected currency for achievement script hGlobalAchievementControllerCS.incrementAchievementCount(GlobalAchievementControllerCS.GlobalAchievementTypes.Currency); return; } fPowerupStartTime[index] = Time.time; //set the time when powerup collected activatePowerUp(index); //activate powerup if collected hMissionsControllerCS.incrementMissionCount(MissionsControllerCS.MissionTypes.Powerups); //count the collected powerups for mission script //count the collected powerups for global achievements script hGlobalAchievementControllerCS.incrementAchievementCount(GlobalAchievementControllerCS.GlobalAchievementTypes.Powerups); }
/* * FUNCTION: Set the menu to show in front of the HUD Camera */ public void ShowMenu(int index) { CurrentMenu = index; //set the active menu to the currently displayed hSoundManagerCS.playSound(SoundManagerCS.MenuSounds.ButtonTap); //play tap sound updateCurrencyOnHeader(); //update currency on header if (index == (int)ShopMenus.Costumes) { int itemCount = 0; //set the items's parent as the currentTab to make the vertical scroll code work currentTab = (Transform)tShopMenuTransforms[(int)ShopMenus.Costumes].Find("CostumeItemGroup").GetComponent(typeof(Transform)); //enable the ShopCostumeScript of all the costume elements foreach (Transform costumeItem in currentTab) { if (costumeItem.name.Contains("CostumeItem")) { ((ShopCostumeScriptCS)costumeItem.GetComponent(typeof(ShopCostumeScriptCS))).setShopCostumeScriptEnabled(true); itemCount++; //count the number of costumes in the costume shop menu } } currentTab.localPosition = new Vector3(currentTab.localPosition.x, 0, currentTab.localPosition.z); //set the upper and lower limit of the scroll scrollUpperLimit = currentTab.localPosition.y + (itemCount * 15); //scrollLowerLimit = currentTab.localPosition.y-(itemCount*10); } else if (index == (int)ShopMenus.Powerups) { int itemCount = 0; //set the items's parent as the currentTab to make the vertical scroll code work currentTab = (Transform)tShopMenuTransforms[(int)ShopMenus.Powerups].Find("PowerupsItemGroup").GetComponent(typeof(Transform)); //enable the ShopPowerupScript of all the costume elements foreach (Transform costumeItem in currentTab) { if (costumeItem.name.Contains("PowerupItem")) { ((ShopPowerupScriptCS)costumeItem.GetComponent(typeof(ShopPowerupScriptCS))).setShopPowerupScriptEnabled(true); itemCount++; //count the number of power-ups in power-up shop menu } } currentTab.localPosition = new Vector3(currentTab.localPosition.x, 0, currentTab.localPosition.z); //set the upper and lower limit of the scroll scrollUpperLimit = currentTab.localPosition.y + (itemCount * 15); //scrollLowerLimit = currentTab.localPosition.y-(itemCount*10); } else if (index == (int)ShopMenus.Utilities) { int itemCount = 0; //set the items's parent as the currentTab to make the vertical scroll code work currentTab = (Transform)tShopMenuTransforms[(int)ShopMenus.Utilities].Find("UtilitiesItemGroup").GetComponent(typeof(Transform)); //enable the ShopUtilityScript of all the costume elements foreach (Transform costumeItem in currentTab) { if (costumeItem.name.Contains("UtilityItem")) { ((ShopUtilityScriptCS)costumeItem.GetComponent(typeof(ShopUtilityScriptCS))).setShopUtilityScriptEnabled(true); itemCount++; //count the number of utilities in utility shop menu } } currentTab.localPosition = new Vector3(currentTab.localPosition.x, 0, currentTab.localPosition.z); //set the upper and lower limit of the scroll scrollUpperLimit = currentTab.localPosition.y + (itemCount * 15); //scrollLowerLimit = currentTab.localPosition.y-(itemCount*10); } else if (index == (int)ShopMenus.IAPs) { int itemCount = 0; //set the items's parent as the currentTab to make the vertical scroll code work currentTab = (Transform)tShopMenuTransforms[(int)ShopMenus.IAPs].Find("IAPItemGroup").GetComponent(typeof(Transform)); //enable the ShopIAPScript of all the costume elements foreach (Transform costumeItem in currentTab) { if (costumeItem.name.Contains("IAPItem")) { ((ShopIAPScriptCS)costumeItem.GetComponent(typeof(ShopIAPScriptCS))).setShopIAPScriptEnabled(true); //enable script itemCount++; //count the number of items in more coins shop menu } } currentTab.localPosition = new Vector3(currentTab.localPosition.x, 0, currentTab.localPosition.z); //set the upper and lower limit of the scroll scrollUpperLimit = currentTab.localPosition.y + (itemCount * 15); //scrollLowerLimit = currentTab.localPosition.y-(itemCount*10); } //end of else if IAPs //move the more menu in front of the HUD camera tShopMenuTransforms[index].position = new Vector3(tShopMenuTransforms[index].position.x, 0, tShopMenuTransforms[index].position.z); } //end of Show Menu function
void FixedUpdate() { if (hInGameScriptCS.isGamePaused() == true) { return; } //set the position of guard in current frame tEnemy.position = new Vector3(Mathf.Lerp(tEnemy.position.x, (tPlayer.position.x - fEnemyPosition), Time.deltaTime * 10), tEnemy.position.y, tEnemy.position.z); if (!hControllerScriptCS.isInAir()) //follow the player in y-axis if he's not jumping (cars cant jump) { tEnemy.position = new Vector3(tEnemy.position.x, Mathf.Lerp(tEnemy.position.y, tPlayer.position.y + fEnemyPositionY, Time.deltaTime * 8), tEnemy.position.z); } //ignore y-axis rotation and horizontal movement in idle and death state if (iEnemyState < 4) { tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y, Mathf.Lerp(tEnemy.position.z, tPlayer.position.z, Time.deltaTime * 10)); tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, -hControllerScriptCS.getCurrentPlayerRotation(), tEnemy.localEulerAngles.z); } if (iEnemyState == 1) //hide the chasing character { fCosLerp += (Time.deltaTime / 10); fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 45, Mathf.Cos(fCosLerp) / 1000); if (fCosLerp >= 0.7f) { fCosLerp = 0.0f; iEnemyState = 0; hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren); } } else if (iEnemyState == 2) //show the chasing character { hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.Siren); fCosLerp += (Time.deltaTime / 4); fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX, Mathf.Cos(fCosLerp)); if (fCosLerp >= 1.5f) { fCosLerp = 0.0f; iEnemyState = 3; } } else if (iEnemyState == 3) //wait for 'fChaseTime' after showing character { if ((Time.time - fStumbleStartTime) % 60 >= fChaseTime) { iEnemyState = 1; } } //DEATH SEQUENCE else if (iEnemyState == 4) //on death { //to ensure correct rotation animation tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, 350, tEnemy.localEulerAngles.z); hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.TiresSqueal); iEnemyState = 5; } else if (iEnemyState == 5) //pin behind the player { fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 20, Time.fixedDeltaTime * 50); //vertical position after skid tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y, Mathf.Lerp(tEnemy.position.z, tPlayer.position.z + 20, Time.deltaTime * 10)); //horizontal position after skid tEnemy.localEulerAngles = Vector3.Lerp(tEnemy.localEulerAngles, new Vector3(0, 260, 0), Time.deltaTime * 10); //90 degree rotation if (tEnemy.localEulerAngles.y <= 261) { iEnemyState = 6; } } else if (iEnemyState == 6) { hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren); } } //end of Update
void FixedUpdate() { if (hInGameScriptCS.isGamePaused() == true) { return; } //set the position of guard in current frame /* * tEnemy.position = new Vector3(Mathf.Lerp(tEnemy.position.x, (tPlayer.position.x - fEnemyPosition), Time.deltaTime*10), * tEnemy.position.y, tEnemy.position.z); */ Matrix4x4 mat = new Matrix4x4(); mat.SetTRS(new Vector3(0, 0, 0), Quaternion.Euler(new Vector3(0, -hControllerScriptCS.getCurrentPlayerRotation(), 0)), new Vector3(1, 1, 1)); Vector3 pos = mat.MultiplyVector(new Vector3(-fEnemyPosition, 0, 0)); tEnemy.position = new Vector3(Mathf.Lerp(tEnemy.position.x, (tPlayer.position.x + pos.x), Time.deltaTime * 10), tEnemy.position.y, // Mathf.Lerp(tEnemy.position.y, (tPlayer.position.y - pos.y), Time.deltaTime*10), Mathf.Lerp(tEnemy.position.z, (tPlayer.position.z + pos.z), Time.deltaTime * 10)); if (!hControllerScriptCS.isInAir()) //follow the player in y-axis if he's not jumping (cars cant jump) { tEnemy.position = new Vector3(tEnemy.position.x, Mathf.Lerp(tEnemy.position.y, tPlayer.position.y + fEnemyPositionY, Time.deltaTime * 8), tEnemy.position.z); } else { RaycastHit hitInfo; if (Physics.Linecast(tEnemy.position + new Vector3(0, 20, 0), tEnemy.position + new Vector3(0, -100, 0), out hitInfo, (1 << LayerMask.NameToLayer("Terrain_lyr")))) { tEnemy.position = new Vector3(tEnemy.position.x, Mathf.Lerp(tEnemy.position.y, hitInfo.point.y + fEnemyPositionY, Time.deltaTime * 8), tEnemy.position.z); } } //ignore y-axis rotation and horizontal movement in idle and death state if (iEnemyState < 4) { // Vector3 pos = mat.MultiplyVector(new Vector3( 0, 0, 0)); //tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y, Mathf.Lerp(tEnemy.position.z, tPlayer.position.z, Time.deltaTime*10)); tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, -hControllerScriptCS.getCurrentPlayerRotation(), tEnemy.localEulerAngles.z); } if (iEnemyState == 1) //hide the chasing character { fCosLerp += (Time.deltaTime / 10); fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 45, Mathf.Cos(fCosLerp) / 1000); if (fCosLerp >= 0.7f) { fCosLerp = 0.0f; iEnemyState = 0; hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren); } } else if (iEnemyState == 2) //show the chasing character { hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.Siren); fCosLerp += (Time.deltaTime / 4); fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX, Mathf.Cos(fCosLerp)); if (fCosLerp >= 1.5f) { fCosLerp = 0.0f; iEnemyState = 3; } } else if (iEnemyState == 3) //wait for 'fChaseTime' after showing character { if ((Time.time - fStumbleStartTime) % 60 >= fChaseTime) { iEnemyState = 1; } } //DEATH SEQUENCE else if (iEnemyState == 4) //on death { //to ensure correct rotation animation tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, 350 - hControllerScriptCS.getCurrentPlayerRotation(), tEnemy.localEulerAngles.z); hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.TiresSqueal); iEnemyState = 5; } else if (iEnemyState == 5) //pin behind the player { fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 20, Time.fixedDeltaTime * 50); //vertical position after skid // tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y, // Mathf.Lerp(tEnemy.position.z, tPlayer.position.z + 20, Time.deltaTime*10));//horizontal position after skid tEnemy.localEulerAngles = Vector3.Lerp(tEnemy.localEulerAngles, new Vector3(0, 260 - hControllerScriptCS.getCurrentPlayerRotation(), 0), Time.deltaTime * 10); //90 degree rotation if (tEnemy.localEulerAngles.y <= 261) { iEnemyState = 6; } } else if (iEnemyState == 6) { hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren); } } //end of Update