퍼즐 보드판 제작과 Cell + 이미지 동적 생성

 

실행 이미지

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;

public class PuzzleMain : MonoBehaviour
{
    public int width = 7;
    public int height = 7;

    public GameObject puzzleCell;
    public Transform grid;

    private GameObject[,] board;


    public Sprite[] fruits;

    void Start()
    {
        board = new GameObject[width, height];

        FillBoard();
    }

    void FillBoard()
    {
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                Vector2 position = new Vector2(i, j);
                int randomIndex = Random.Range(0, fruits.Length);
                GameObject piece = Instantiate(puzzleCell, grid.transform);
                piece.GetComponent<Cell>().fruit.sprite = fruits[randomIndex];

                board[i, j] = piece;
            }
        }
    }
}

PuzzleMain.cs

 

 

 

사용할 PuzzleCell 이미지(Sprite)

 

Cell Frame
Cell Focus

 

+ Recent posts