Unity Tilemap의 SetTile을 사용하면 타일 설정이 가능하다.
참고자료
https://docs.unity3d.com/ScriptReference/Tilemaps.Tilemap.SetTile.html
Unity - Scripting API: Tilemaps.Tilemap.SetTile
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
활용 코드
using UnityEngine;
using UnityEngine.Tilemaps;
public class Board : MonoBehaviour
{
public Tilemap tilemap { get; private set; }
private void Awake()
{
tilemap = GetComponent<Tilemap>();
}
/// <summary>
/// state의 행과 열의 크기만큼 tilemap을 설정한다.
/// </summary>
public void Draw(Cell[,] state)
{
int width = state.GetLength(0); // 행의 개수
int height = state.GetLength(1); // 열의 개수
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Cell cell = state[x, y];
tilemap.SetTile(cell.position, GetTile(cell));
}
}
}
private Tile GetTile(Cell cell)
{
//...원하는 타일을 리턴한다.
return tile;
}
}'개발툴 > Unity' 카테고리의 다른 글
| Reflex (Github Readme 번역) (1) | 2023.12.18 |
|---|---|
| Unity에서 ChatGPT 사용하기 (0) | 2023.10.24 |
| IL2CPP (0) | 2023.09.30 |
| Null 레퍼런스 예외 해결방법 (0) | 2023.07.28 |
| <시간 및 프레임 속도 관리> (0) | 2023.07.16 |