Esempio n. 1
0
    // Check for player digging and destroy rocks
    void RockDigging()
    {
        // Loop through all cubes in the cubes list
        foreach (GameObject cube in cubes)
        {
            // Check that there are cubes
            if (cubes.Count > 0 && cube != null)
            {
                // Get the cube data
                CubeData cubeData = cube.GetComponent <CubeData>();

                // If the cube can be destroyed and the player is digging and if health of the cubes is greater than 0
                if (cubeData.CubeDestructible() && diggingAttacking && cubeData.CurrentHealth() > 0)
                {
                    cubeData.CubeDamaged(1);
                }
            }
        }

        // If there are cubes in the cubes list
        if (cubes.Count > 0)
        {
            // Loop through each cube
            for (int i = 0; i < cubes.Count; i++)
            {
                // If the cube has been destroyed remove it from the cubes list
                if (cubes[i] == null || cubes[i].GetComponent <CubeData>().CubeDestroyed())
                {
                    cubes.Remove(cubes[i].gameObject);
                }
            }
        }
    }
Esempio n. 2
0
    // Check if explosion destroys rocks
    void DestroyGridCubes()
    {
        // Loop through all cubes in the cubes list
        foreach (GameObject cube in cubes)
        {
            // Check that there are cubes
            if (cubes.Count > 0 && cube != null)
            {
                // Get the cube data
                CubeData cubeData = cube.GetComponent <CubeData>();

                // If the cube can be destroyed
                if (cubeData.CubeDestructible())
                {
                    cubeData.CubeDamaged(cubeData.CurrentHealth());
                }
            }
        }

        // If there are cubes in the cubes list
        if (cubes.Count > 0)
        {
            // Loop through each cube
            for (int i = 0; i < cubes.Count; i++)
            {
                // If the cube has been destroyed remove it from the cubes list
                if (cubes[i] == null || cubes[i].GetComponent <CubeData>().CubeDestroyed())
                {
                    cubes.Remove(cubes[i].gameObject);
                }
            }
        }

        // Play the particles
        ParticleSystemController.InstaniateParticleSystem(explosion, transform.position, Quaternion.identity);
    }