Exemplo n.º 1
0
    // Edge decetion along one axis
    void EdgeDetection(int offsetX, int offsetZ, bool initialCheck = true)
    {
        // Assign references to the cube gameobject and cubedata script
        GameObject cube     = map.GridCubeArray()[(int)cubeCoord.x + offsetX, (int)cubeCoord.z + offsetZ];
        CubeData   cubeData = cube.GetComponent <CubeData>();

        // If the cube exsists on the x axis and is not of type metal e.g. (border)
        if (cube.gameObject != null && cubeData.cubeType != CUBETYPE.BORDER)
        {
            // If the edge detection is during map generation
            if (initialCheck)
            {
                // Set the cube as an edge cube - update material
                cubeData.SetAsEdgeCube();

                // If the edge cube is a cyrstal cube change it to a rock cube
                if (cubeData.cubeType == CUBETYPE.CRYSTAL)
                {
                    cubeData.SetAsRockCube();
                    cubeData.SetAsEdgeCube();
                }
            }

            // Else if the edge dectetion is in game
            else if (!initialCheck && cubeData.cubeType == CUBETYPE.ROCK && cube.GetComponent <MeshRenderer>() != null)
            {
                cubeData.SetAsEdgeCube();
            }
        }
    }