// Use this for initialization
    void Start()
    {
        if (this.name == "BossRoom(Clone)")
        {
            bigDoor = GameObject.FindGameObjectWithTag("bigDoor");
        }
        int n = 0;
        int i;

        allDoors = GameObject.FindGameObjectsWithTag("door");
        doors    = allDoors;
        for (i = 0; i < allDoors.Length; i++)
        {
            if (allDoors[i].transform.IsChildOf(this.transform))
            {
                doors[n] = allDoors[i];
                //			mydoor = allDoors[i];
                n++;
            }
        }
        while (n < i)
        {
            doors[n] = null;
            n++;
        }
        CellScript = GameObject.FindGameObjectWithTag("cell").GetComponent <CellMover>();
        for (int a = 0; a < Random.Range(minBarriers, maxBarriers); a++)
        {
            Instantiate(barriers[Random.Range(0, barriers.Length)], new Vector2((transform.position.x + Random.Range(2 - width, width - 2)),
                                                                                (transform.position.y + Random.Range(2 - height, height - 2))), Quaternion.Euler(0, 0, Random.Range(0, 360)));
        }
    }
示例#2
0
    //  Use this for initialization
    public void Start()
    {
        colors = new Color[6] {
            Color.red, Color.cyan, Color.yellow, Color.green, Color.magenta, Color.blue
        };
//		cameraM = GameObject.FindGameObjectWithTag("Player");
        roomsPositions = new int[20, 20] {
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
        };
        if (GameObject.FindWithTag("cell") == null)
        {
            switch (PlayerPrefs.GetString("PlayerPers"))
            {
            case "Biotic1":
                Instantiate(playerPers [0], transform.position, transform.rotation);
                break;

            case "Biotic2":
                Instantiate(playerPers [1], transform.position, transform.rotation);
                lsdBool = true;
                break;

            case "Biotic3":
                Instantiate(playerPers [2], transform.position, transform.rotation);
                break;

            case "Cyborg1":
                Instantiate(playerPers [3], transform.position, transform.rotation);
                break;

            case "Cyborg2":
                Instantiate(playerPers [4], transform.position, transform.rotation);
                break;

            case "Cyborg3":
                Instantiate(playerPers [5], transform.position, transform.rotation);
                break;

            case "Nanobot1":
                Instantiate(playerPers [6], transform.position, transform.rotation);
                break;

            case "Nanobot2":
                Instantiate(playerPers [7], transform.position, transform.rotation);
                break;

            case "Nanobot3":
                Instantiate(playerPers [8], transform.position, transform.rotation);
                break;

            default:
                Instantiate(playerPers [0], transform.position, transform.rotation);
                break;
            }
        }
        GameObject room = startRoom;

        TopRight = Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0));
        int i = 10;
        int j = 10;
        int dir;
        int numberOfRooms = Random.Range(6, 9);

        for (int a = 0; a <= numberOfRooms; a += 0)
        {
            if (roomsPositions[i, j] != 1)
            {
                a++;
            }
            roomsPositions [i, j] = 1;
            do
            {
                dir = Random.Range(0, 3);
                switch (dir)
                {
                case 0:
                    i++;
                    break;

                case 1:
                    j++;
                    break;

                case 2:
                    i--;
                    break;

                case 3:
                    j--;
                    break;
                }
            }while(i < 0 || j < 0 || i > 19 || j > 19);
        }
        //new Color[]{Color.red, Color.green, Color.cyan, Color.yellow};
        float currX = 0;
        float currY = 0;

        for (int l = 0; l <= 19; l++)
        {
            for (int m = 0; m <= 19; m++)
            {
                if (roomsPositions[l, m] == 1)
                {
                    if ((l < 19) && (roomsPositions[l + 1, m] == 0) && !BossRoomSet)
                    {
                        roomsPositions[l + 1, m] = 2;
                        BossRoomSet = true;
                        currX       = (l + 1) * 2 * room.GetComponent <RoomScript>().width;
                        currY       = m * 2 * room.GetComponent <RoomScript>().height;
                        clone       = Instantiate(bossRoom, new Vector2(currX, currY), transform.rotation) as GameObject;
                        if (l < 19 && roomsPositions[l + 2, m] > 0)
                        {
                            clone.transform.FindChild("Right").FindChild("door").gameObject.tag = "door";
                        }
                        else if (!bigDoorSpawned)
                        {
                            clone.transform.FindChild("Right").FindChild("door").gameObject.tag = "bigDoor";
                            bigDoorSpawned = true;
                        }
                        if (l > 0 && roomsPositions[l, m] > 0)
                        {
                            clone.transform.FindChild("Left").FindChild("door").gameObject.tag = "door";
                        }
                        else if (!bigDoorSpawned)
                        {
                            clone.transform.FindChild("Left").FindChild("door").gameObject.tag = "bigDoor";
                            bigDoorSpawned = true;
                        }
                        if (m < 19 && roomsPositions[l + 1, m + 1] > 0)
                        {
                            clone.transform.FindChild("Top").FindChild("door").gameObject.tag = "door";
                        }
                        else if (!bigDoorSpawned)
                        {
                            clone.transform.FindChild("Top").FindChild("door").gameObject.tag = "bigDoor";
                            bigDoorSpawned = true;
                        }
                        if (m > 0 && roomsPositions[l + 1, m - 1] > 0)
                        {
                            clone.transform.FindChild("Bottom").FindChild("door").gameObject.tag = "door";
                        }
                        else if (!bigDoorSpawned)
                        {
                            clone.transform.FindChild("Bottom").FindChild("door").gameObject.tag = "bigDoor";
                            bigDoorSpawned = true;
                        }
                    }
                    currX = l * 2 * room.GetComponent <RoomScript>().width;
                    currY = m * 2 * room.GetComponent <RoomScript>().height;
                    clone = Instantiate(room, new Vector2(currX, currY), transform.rotation) as GameObject;
                    if (l < 19 && roomsPositions[l + 1, m] > 0)
                    {
                        clone.transform.FindChild("Right").FindChild("door").gameObject.tag = "door";
                    }
                    if (l > 0 && roomsPositions[l - 1, m] > 0)
                    {
                        clone.transform.FindChild("Left").FindChild("door").gameObject.tag = "door";
                    }
                    if (m < 19 && roomsPositions[l, m + 1] > 0)
                    {
                        clone.transform.FindChild("Top").FindChild("door").gameObject.tag = "door";
                    }
                    if (m > 0 && roomsPositions[l, m - 1] > 0)
                    {
                        clone.transform.FindChild("Bottom").FindChild("door").gameObject.tag = "door";
                    }
                    room = possibleRooms[Random.Range(0, possibleRooms.Length)];
                }
            }
        }
        //	cameraM.transform.parent = transform;
        Cell       = GameObject.FindGameObjectWithTag("cell");
        CellScript = Cell.GetComponent <CellMover> ();
    }