Version: 2022.3
LanguageEnglish
  • C#

Tilemap.SetTiles

Suggest a change

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

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public void SetTiles(Vector3Int[] positionArray, TileBase[] tileArray);

Parameters

positionArray An array of positions of Tiles on the Tilemap.
tileArray An array of Tiles to be placed.

Description

Sets an array of Tiles at the given XYZ coordinates of the corresponding cells in the Tilemap.

Refer to Scriptable Tiles and Tilemap for more information.

// Fills Tilemap area with checkerboard pattern of tileA and tileB
using UnityEngine;
using UnityEngine.Tilemaps;

public class ExampleClass : MonoBehaviour { public TileBase tileA; public TileBase tileB; public Vector2Int size;

void Start() { Vector3Int[] positions = new Vector3Int[size.x * size.y]; TileBase[] tileArray = new TileBase[positions.Length];

for (int index = 0; index < positions.Length; index++) { positions[index] = new Vector3Int(index % size.x, index / size.y, 0); tileArray[index] = index % 2 == 0 ? tileA : tileB; }

Tilemap tilemap = GetComponent<Tilemap>(); tilemap.SetTiles(positions, tileArray); } }

Declaration

public void SetTiles(TileChangeData[] tileChangeDataArray, bool ignoreLockFlags);

Parameters

tileChangeDataArray The array of Tiles with additional properties to place.
ignoreLockFlags Whether to ignore Lock Flags set in the Tile's TileFlags when applying Color and Transform changes from TileChangeData.

Description

Sets an array of Tiles with additonal properties at the given XYZ coordinates of the corresponding cells in the Tilemap. The Color and Transform of the TileChangeData will take precedence over the values from the Tile.

Refer to Scriptable Tiles and Tilemap for more information.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961