Exemplo n.º 1
0
    // if (AllObjectData.instance.posY >= item.fromHeight && AllObjectData.instance.posY <= item.toHeight)
    /// <summary>
    /// Choosing Random Prefab to Spawn
    /// </summary>
    /// <returns></returns>
    private NameAndNumberDto ChoseGround()
    {
        List <GroundScriptable> listOfGroundToSpawn = new List <GroundScriptable>();

        foreach (var item in groundScriptable)
        {
            if (Mathf.Abs(AllObjectData.instance.posX) >= item.spawnXRadiusMin && Mathf.Abs(AllObjectData.instance.posX) <= item.spawnXRadiusMax)
            {
                listOfGroundToSpawn.Add(item);
            }
        }
        //If no object found
        if (listOfGroundToSpawn == null || listOfGroundToSpawn.Count == 0)
        {
            return(new NameAndNumberDto
            {
                Name = groundScriptable[0].groundName,
                size = groundScriptable[0].groundSize
            });
        }
        int numberOfObjectToSpawn         = MainCount.instance.IntegerRandom(0, listOfGroundToSpawn.Count);
        NameAndNumberDto nameAndNumberDto = new NameAndNumberDto()
        {
            Name = listOfGroundToSpawn[numberOfObjectToSpawn].groundName,
            size = listOfGroundToSpawn[numberOfObjectToSpawn].groundSize
        };

        return(nameAndNumberDto);
    }
Exemplo n.º 2
0
    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;
    }