private void GenerateGround() { NameAndNumberDto groundNameAndSize = ChoseGround(); if (groundNameAndSize == null) { return; } float startingPosition; int modifier; if (AllObjectData.instance.posX > 0) { modifier = 1; } else { modifier = -1; } if (Mathf.Abs(AllObjectData.instance.posX) <= spawnBorder + groundNameAndSize.size * groundObjectMax / 2) { startingPosition = modifier * (spawnBorder + 10); } else { startingPosition = Mathf.Round(AllObjectData.instance.posX - AllObjectData.instance.posX % groundNameAndSize.size) - 2 * groundNameAndSize.size * modifier; } if (modifier > 0) { for (int i = 1; i <= 5; i++) { Vector3 groundPosition = new Vector3(startingPosition + i * modifier * groundNameAndSize.size, baseSpawnY, 0); objectPoolList.GetPooledObject(groundNameAndSize.Name, groundPosition, Quaternion.identity, false); } } else { for (int i = 5; i >= 1; i--) { Vector3 groundPosition = new Vector3(startingPosition + i * modifier * groundNameAndSize.size, baseSpawnY, 0); objectPoolList.GetPooledObject(groundNameAndSize.Name, groundPosition, Quaternion.identity, false); } } landGenerated = true; groundBlockMover.enabled = true; }
private void SpawnFlyingObject(string poolName) { //print(poolName); //Geting List of Objects whitch can be spawned on player's Height List <AirObjectScriptable> listOfObjectsOnThisHeight = new List <AirObjectScriptable>(); var listOfAirObjects = airObjectByTypeArray.FirstOrDefault(n => n.poolName == poolName); foreach (var item in listOfAirObjects.airObjectList) { if (AllObjectData.instance.posY <= item.maxHeight && AllObjectData.instance.posY >= item.minHeight) { listOfObjectsOnThisHeight.Add(item); } } //If no object found if (listOfObjectsOnThisHeight == null || listOfObjectsOnThisHeight.Count == 0) { return; } //Object flies from left to right? float objectXposition; if (MainCount.instance.BoolRandom()) { objectXposition = -nodeInformer.cameraXWidth - objectSpawnOffset; } else { objectXposition = nodeInformer.cameraXWidth + objectSpawnOffset; } int[] airObjectWeights = new int[listOfObjectsOnThisHeight.Count]; for (int i = 0; i < listOfObjectsOnThisHeight.Count; i++) { airObjectWeights[i] = listOfObjectsOnThisHeight[i].spawnChance; } int numberOfObjectToSpawn = MainCount.instance.DifferentWeightRandom(airObjectWeights);//mainCount.IntegerRandom(0, listOfObjectsOnThisHeight.Count); float startingYposToSpawn = MainCount.instance.FloatRandom(higherFromPlayerToSpawnMin, higherFromPlayerToSpawnMax); if ((AllObjectData.instance.gameobjectVelocity.x * AllObjectData.instance.gameobjectVelocity.x > ConstsLibrary.speedSquareAferSpawnObjectOnMinHeight)) { startingYposToSpawn = MainCount.instance.FloatRandom(-ConstsLibrary.heightToSpawnWhenXisHigh, ConstsLibrary.heightToSpawnWhenXisHigh); } if (AllObjectData.instance.gameobjectVelocity.y < 0 && AllObjectData.instance.posY > higherFromPlayerToSpawnMax) { startingYposToSpawn *= -1; } string name = listOfObjectsOnThisHeight[numberOfObjectToSpawn].objectName; float xPosition; if (AllObjectData.instance.gameobjectVelocity.x >= 0) { if (objectXposition < 0) { xPosition = AllObjectData.instance.posX + objectXposition; } else { xPosition = AllObjectData.instance.posX + objectXposition + AllObjectData.instance.gameobjectVelocity.x; } } else { if (objectXposition > 0) { xPosition = AllObjectData.instance.posX + objectXposition; } else { xPosition = AllObjectData.instance.posX + objectXposition + AllObjectData.instance.gameobjectVelocity.x; } } Vector3 position = new Vector3(xPosition//AllObjectData.instance.posX + objectXposition + AllObjectData.instance.gameobjectVelocity.x , AllObjectData.instance.posY + startingYposToSpawn + AllObjectData.instance.gameobjectVelocity.y); objectPoolList.GetPooledObject(name, position, Quaternion.identity, true); ///SpawningObject }