워리어 콤보 모작 개발일지

워리어콤보 개발일지 - Test [보드생성]

다모아 2023. 9. 15. 14:41

STEP.2.txt
0.00MB
STEP.1.txt
0.00MB
목표.txt
0.00MB

using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.UI;

public class TestMain : MonoBehaviour
{
    [SerializeField]
    private GameObject wallPrefab;
    [SerializeField]
    private GameObject blockPrefab;
    [SerializeField]
    private Transform boardTr;
    private TestBlock testBlock;
    private int[,] str =
    {
        {0, 0, 4, 2, 4, 0, 0},
        {0, 0, 5, 1, 2, 0, 0},
        {0, 0, 5, 4, 3, 0, 0},
        {0, 0, 1, 2, 3, 0, 0},
        {0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0}
    };

    // Start is called before the first frame update
    void Start()
    {
        this.testBlock = new TestBlock();

        for(int row = 0; row < 7; row++)
        {
            for(int col = 0; col < 7; col++)
            {
                switch (str[row, col])
                {
                    case 0:
                        testBlock.Move(row, col);
                        testBlock.InstantiateObj(this.wallPrefab, this.boardTr, TestBlock.eBlockType.WALL);
                        break;
                    case 1:
                        testBlock.Move(row, col);
                        testBlock.InstantiateObj(this.blockPrefab, this.boardTr, TestBlock.eBlockType.RED);
                        break;
                    case 2:
                        testBlock.Move(row, col);
                        testBlock.InstantiateObj(this.blockPrefab, this.boardTr, TestBlock.eBlockType.BLUE);
                        break;
                    case 3:
                        testBlock.Move(row, col);
                        testBlock.InstantiateObj(this.blockPrefab, this.boardTr, TestBlock.eBlockType.GREEN);
                        break;
                    case 4:
                        testBlock.Move(row, col);
                        testBlock.InstantiateObj(this.blockPrefab, this.boardTr, TestBlock.eBlockType.YELLOW);
                        break;
                    case 5:
                        testBlock.Move(row, col);
                        testBlock.InstantiateObj(this.wallPrefab, this.boardTr, TestBlock.eBlockType.PURPLE);
                        break;

                }
            }
        }
    }

    private void Update()
    {
        Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Ray2D ray = new Ray2D(pos, Vector2.zero);
        RaycastHit2D hit;
        if(Physics2D.Raycast(ray.origin, ray.direction))
        {

        }
    }

}

 

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

public class TestBlock : MonoBehaviour
{
    private int nRow;
    private int nCol;

    public enum eBlockType
    {
        WALL = 0,
        RED = 1,
        BLUE = 2,
        GREEN = 3,
        YELLOW = 4,
        PURPLE = 5,
    }

    public void InstantiateObj(GameObject objPrefab, Transform boardTr, eBlockType type)
    {
        GameObject obj = Instantiate(objPrefab, boardTr);

        obj.transform.position = boardTr.position + new Vector3(nCol, nRow);

        SpriteRenderer objSp = obj.GetComponent<SpriteRenderer>();

        objSp.sprite = Resources.Load<Sprite>($"Test/{type}");

    }

    public void Move(int row, int col)
    {
        this.nRow = row;
        this.nCol = col;
    }
}