Пример #1
0
    void MakeWaterTile(int row, int col)
    {
        Destroy(GameObject.Find(MakeTileName(row, col)));
        GameObject tile;
        Vector3    pos = new Vector3(row, col, 0);

        tile = (GameObject)GameObject.Instantiate(waterTilePrefab);

        tile.transform.parent        = gameObject.transform;
        tile.transform.localPosition = pos;
        tile.name = MakeTileName(row, col);
        ClickReporter cr = tile.AddComponent <ClickReporter>();

        cr.row          = row;
        cr.col          = col;
        cr.reportTarget = gameObject;
    }
Пример #2
0
    void PlaceTiles()
    {
        totalTreasures = 0;
        int numRows = 10;
        int numCols = 10;

        for (int row = 0; row < numRows; row += 1)
        {
            for (int col = 0; col < numCols; col += 1)
            {
                Vector3    pos = new Vector3(row, col, 0);
                GameObject tile;
                switch (levelData[row][col])
                {
                default:
                case '0':
                    tile = (GameObject)GameObject.Instantiate(waterTilePrefab);
                    break;

                case '1':
                    tile = (GameObject)GameObject.Instantiate(landTilePrefab);
                    break;

                case '2':
                    tile = (GameObject)GameObject.Instantiate(mineTilePrefab);
                    break;

                case '3':
                    tile = (GameObject)GameObject.Instantiate(waterTilePrefab);

                    GameObject sharkGO = (GameObject)GameObject.Instantiate(sharkPrefab);
                    sharkGO.transform.parent = gameObject.transform;
                    Vector3 sharkPos = pos;
                    sharkPos.z = -0.5f;                         // start it on top of the given tile in the map, but below the ship
                    sharkGO.transform.localPosition = sharkPos;
                    Shark shark = sharkGO.GetComponent <Shark>();
                    shark.row   = row;
                    shark.col   = col;
                    shark.board = this;
                    break;

                case '4':
                    tile = (GameObject)GameObject.Instantiate(waterTilePrefab);

                    GameObject treasureGO = (GameObject)GameObject.Instantiate(treasurePrefab);
                    treasureGO.transform.parent = gameObject.transform;
                    Vector3 treasurePos = pos;
                    treasurePos.z = -0.75f;                     // above tiles and sharks, below ship
                    treasureGO.transform.localPosition = treasurePos;
                    treasureGO.name = "treasure_" + MakeTileName(row, col);

                    totalTreasures += 1;
                    break;

                case '5':
                    tile = (GameObject)GameObject.Instantiate(waterTilePrefab);
                    playerStartPosition = new Vector2(row, col);

                    break;
                }
                tile.transform.parent        = gameObject.transform;
                tile.transform.localPosition = pos;
                tile.name = MakeTileName(row, col);
                ClickReporter cr = tile.AddComponent <ClickReporter>();
                cr.row          = row;
                cr.col          = col;
                cr.reportTarget = gameObject;
            }
        }
    }