// Update is called once per frame void Update() { float timePassed = 100 * Time.deltaTime * levelObj.GetComponent <WorldSpin>().speed / GameObject.FindGameObjectWithTag("Snowboard").GetComponent <Snowboard>().maxSpeed; if (!levelRunning) { return; } if (airborne) { if (airscoreFrameCount == airScoreNFramesTick) { addAirborneScore(airScoreBase * timesPassedAirScore); airscoreFrameCount = 0; timesPassedAirScore++; } else { airscoreFrameCount++; } } timeInSeconds += Time.deltaTime; if (slalomEvent) { // -- Spawning -- if (currentSlalomCheckpointCount <= NUMBER_OF_SLALOMS) { if (slalomTimer == 0) { spawner.CreateSlalomFlag(); canSpawnSlalomCheckpoint = true; slalomTimer += timePassed; } else if (slalomTimer >= TIME_BETWEEN_SLALOMS) { slalomTimer = 0; } else if (slalomTimer >= SLALOM_CHECKPOINT_TIMER && canSpawnSlalomCheckpoint) { spawner.CreateSlalomCheckpoint(); canSpawnSlalomCheckpoint = false; // So we only spawn 1 checkpoint per slalom currentSlalomCheckpointCount++; } else { slalomTimer += timePassed; } } else { slalomEvent = false; slalomTimer = 0; currentSlalomCheckpointCount = 0; } } else if (bonusEvent) { // -- Spawning -- if (currentBonusCashCount <= EVENT_COLD_CASH) { if (bonusTimer == 0) { spawner.CreateBonusCash(); currentBonusCashCount++; bonusTimer += timePassed; } else if (bonusTimer >= TIME_BETWEEN_CASH) { bonusTimer = 0; } else { bonusTimer += timePassed; } } else { bonusEvent = false; bonusTimer = 0; currentBonusCashCount = 0; } } else if (stopSpawning) { if (levelEndSpawnTimer >= LEVEL_END_DELAY) { spawner.CreateLevelEnd(); } else { levelEndSpawnTimer += timePassed; } } else if (!stopSpawning) { if (ShouldSpawnLevelEnd()) { //spawner.CreateLevelEnd(); stopSpawning = true; return; // Don't bother running the rest of Update } if (ShouldStartSlalom()) { slalomEvent = true; canSpawnSlalomCheckpoint = false; slalomTimer = -1; } if (ShouldStartBonus()) { bonusEvent = true; bonusTimer = -1; } if (ShouldSpawnObstacle()) { spawner.CreateObstacle(); } if (ShouldSpawnRamp()) { spawner.CreateRamp(); } if (ShouldSpawnCash()) { spawner.CreateColdCash(); } if (ShouldSpawnPickup()) { // Randomly choose a pickup to spawn float decision = Random.Range(0, 1.0f); if (decision < 0.33f) { spawner.CreateBoostPickup(); } else if (decision < 0.66f) { spawner.CreateCashBonusPickup(); } else { spawner.CreateMultiplierPickup(); } } obstacleSpawnTimer += timePassed; rampSpawnTimer += timePassed; cashSpawnTimer += timePassed; pickupSpawnTimer += timePassed; levelEndSpawnTimer += timePassed; slalomTimer += timePassed; bonusTimer += timePassed; gameScreen.SetDistancePercent((float)levelEndSpawnTimer / (float)LEVEL_END_SPAWN_INTERVAL); } }