Exemplo n.º 1
0
    private void MarkAsPath(int i, int j)
    {
        grids[i, j].GetComponent <Renderer>().material.color = pathColor;
        grids[i, j].GetComponent <GameGrid>().structure      = structureType.PATH;
        grids[i, j].transform.position = new Vector3(grids[i, j].transform.position.x, grids[i, j].transform.position.y - 1, grids[i, j].transform.position.z);
        Vector3 trans = new Vector3(grids[i, j].transform.position.x, -1, grids[i, j].transform.position.y);

        PathVectors.Add(grids[i, j].transform.position);
    }
Exemplo n.º 2
0
    private void GeneratePath()
    {
        Debug.Log($"A tömb: {grids.GetLength(0)},{grids.GetLength(1)}");
        int startX = 0, startY = 0;
        int endX = grids.GetLength(0) - 1, endY = grids.GetLength(1) - 1;

        Debug.Log($"startX: {startX}, startY: {startY}, endX: {endX}, endY: {endY}");
        MarkAsPath(startX, startY);
        PathVectors.Add(new Vector3(startX, -1, startY));

        int xDiff = (int)Mathf.Abs(startX - endX);
        int yDiff = (int)Mathf.Abs(endY - startY);
        int currentX = startX, currentY = startY;

        Debug.Log($"xDiff: {xDiff}, yDiff: {yDiff}");
        Debug.Log($"currentX: {currentX}, currentY: {currentY}");

        while ((currentX != endX) || (currentY != endY))
        {
            int random = UnityEngine.Random.Range(0, 2);
            Debug.Log("Erre megy a random: " + random);

            if (random == 0)
            {
                // tehát x-et sorsoltuk
                if (xDiff > 0)
                {
                    //ha mehetünk még x irányába, akkor menjünk:
                    xDiff--;
                    currentX++;
                    MarkAsPath(currentX, currentY);
                }
            }
            else
            {
                if (yDiff > 0)
                {
                    //ha mehetünk még x irányába, akkor menjünk:
                    yDiff--;
                    currentY++;
                    MarkAsPath(currentX, currentY);
                }
            }
        }

        GameObject portalInstantiated = Instantiate(portal, grids[wideness - 1, depth - 1].transform.position + new Vector3(0f, 1.25f, 0f), Quaternion.identity);

        portalInstantiated.transform.position = new Vector3(portalInstantiated.transform.position.x - 32, portalInstantiated.transform.position.y, portalInstantiated.transform.position.z);
        grids[wideness - 1, depth - 1].GetComponent <GameGrid>().structure = structureType.PORTAL;
        portalInstantiated.transform.localScale             = new Vector3(0.3f, 0.3f, 0.3f);
        portalInstantiated.transform.GetChild(2).localScale = new Vector3(0.3f, 0.3f, 0.3f);
        if (grids[wideness - 2, depth - 1].transform.position.y == 0)
        {
            portalInstantiated.transform.rotation = Quaternion.Euler(new Vector3(0f, 90f, 0f));
        }
        grids[wideness - 1, depth - 1].GetComponent <GameGrid>().objectsHeld[1] = portalInstantiated;
    }