void SpawnMeteor() { var elapsedFromLastSpawnedAt = Time.time - lastSpawnedAt; if (elapsedFromLastSpawnedAt < _spawnInterval) { return; } var transform = this.transform; var meteorGameObject = Instantiate(meteorPrefab, transform); var meteor = meteorGameObject.GetComponent <Meteor>(); meteor.speed = _meteorSpeed; meteor.rotationAxis = normalize(random.NextFloat3()); meteor.rotationSpeed = meteorRotationSpeedRange.x + (meteorRotationSpeedRange.x - meteorRotationSpeedRange.y) * random.NextFloat(); var meteorPosition = meteorGameObject.transform.position; var lanePosition = (Lane.Position)(Mathf.Abs(random.NextInt()) % 3); meteorPosition.x = lane.GetTargetXFromPosition(lanePosition); meteorGameObject.transform.position = meteorPosition; _spawnInterval -= _spawnInterval * spawnIntervalReductionRate * elapsedFromLastSpawnedAt; _meteorSpeed += _meteorSpeed * meteorSpeedIncreaseRate * elapsedFromLastSpawnedAt; var microStarParticleMain = microStarParticle.main; microStarParticleMain.startSpeedMultiplier = _meteorSpeed; lastSpawnedAt = Time.time; }
void OnEnable() { isRunning = false; _traveledLength = 0.0F; movingDirection = null; targetLanePosition = Lane.Position.Center; explodeCompletionSource = new UniTaskCompletionSource(); random.InitState((uint)DateTime.Now.ToBinary()); var rigidbody = GetComponent <Rigidbody>(); rigidbody.isKinematic = true; var position = transform.position; var targetX = lane.GetTargetXFromPosition(targetLanePosition); transform.position = new float3(targetX, 0, 0); transform.rotation = quaternion.identity; body.SetActive(true); }