/* * FUNCTION: Randomise an element to generate on the path * RETURNS: Element number to generate * CALLED BY: Start() * Update() * generateElements() */ private int getRandomElement() { float highestFrequency = 0; int elementIndex = 0; int i = 0; float tempFreq = 0; if (iLastPowerupGenerated > iForcePowerupGeneration && //force powerup generation if not generated for a while !hPowerupsMainControllerCS.isPowerupActive() && //ensure that a powerup is not currently active bPowerupPlaced == false) //do not generate powerup if one is already active { for (i = iObstacleCount; i < (iObstacleCount + iPowerupCount); i++) { tempFreq = elements[i].iFrequency * Random.value; if (highestFrequency < tempFreq) { highestFrequency = tempFreq; elementIndex = i; } } iLastPowerupGenerated = 0; //reset variable } else //normal case; generate any random element { for (i = 0; i < iTotalCount; i++) { if ((elements[i].elementType == ElementType.Powerup && hPowerupsMainControllerCS.isPowerupActive()) || //do not generate powerup if one is already active (elements[i].elementType == ElementType.Powerup && bPowerupPlaced == true)) //do not place powerup on current patch if one has already been placed { continue; } tempFreq = elements[i].iFrequency * Random.value; if (highestFrequency < tempFreq) { highestFrequency = tempFreq; elementIndex = i; } //Debug.Log ("h "+highestFrequency+" f "+elements[i].iFrequency + " r "+Random.value+" t "+tempFreq); } //end of for } //if a powerup has been placed, stop placing more powerups in current patch if (elements[elementIndex].elementType == ElementType.Powerup) { bPowerupPlaced = true; } return(elementIndex); }
void FixedUpdate() { if (hInGameScriptCS.isGamePaused() == true) { return; } if (PUState == 1) //hide the powerup { if (hPowerupsMainControllerCS.isPowerupActive(PowerupsMainControllerCS.PowerUps.Magnetism) == true) //magnetism powerup is active { //adjust the currency's height v3CurrencyLerpPosition = tPlayer.position; v3CurrencyLerpPosition.x += 2; v3CurrencyLerpPosition.y += 5; //pull the currency towards the player transform.position = Vector3.Lerp(transform.position, v3CurrencyLerpPosition, (Time.time - StartTime) / 0.8f); transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(0.1f, 0.1f, 0.1f), (Time.time - StartTime) / 0.8f); } else //regular cases { //pull the currency towards the player transform.position = Vector3.Lerp(transform.position, tPlayer.position, (Time.time - StartTime) / 0.2f); transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(0.01f, 0.01f, 0.01f), (Time.time - StartTime) / 0.002f); } if ((Time.time - StartTime) > 0.2f) { //disable currency if magnetism is activated if (powerupType == PowerupsMainControllerCS.PowerUps.Currency || hPowerupsMainControllerCS.isPowerupActive(PowerupsMainControllerCS.PowerUps.Magnetism) == true) { toggleMeshRenderer(false); //make currency invisible } else { this.gameObject.SetActive(false); //deactivate object } } return; } v3DistanceVector = transform.position - tPlayer.position; //destroy not collect currency/ powerup if (v3DistanceVector.sqrMagnitude < 40000.0f) { bDestroyWhenFarFlag = true; } //destroy currency or powerup if not collected if (bDestroyWhenFarFlag == true) { if (v3DistanceVector.sqrMagnitude > 90000.0f) { if (powerupType == PowerupsMainControllerCS.PowerUps.Currency) { toggleMeshRenderer(false); } else { this.gameObject.SetActive(false); } } } if (powerupType == PowerupsMainControllerCS.PowerUps.Currency) //currency pull radius { fCatchRadius = hPowerupsMainControllerCS.getMagnetismRadius(); } if (v3DistanceVector.sqrMagnitude < fCatchRadius) //catch the orb { PUState = 1; //hide the orb StartTime = Time.time; hPowerupsMainControllerCS.collectedPowerup((int)powerupType); //tell power-up main script what has been collected } //make the power-up spin on if its not currency if (powerupType != PowerupsMainControllerCS.PowerUps.Currency) { this.transform.Rotate(0, Time.deltaTime * 160, 0); } }