Tilemap.GetCellCenterLocal

매뉴얼로 전환
public Vector3 GetCellCenterLocal (Vector3Int position);

파라미터

positionGrid cell position.

반환

Vector3 Center of the cell transformed into local space coordinates.

설명

Get the logical center coordinate of a grid cell in local space.

In a rectangular grid layout, a call to GridLayout.CellToLocal with Vector3Int parameter, returns a Vector3 coordinate that represents the bottom-left of the cell. While mathematically correct, you may prefer the center of the cell, for example when instantiating a GameObject into the grid.

// Snap the GameObject to parent Tilemap center of cell
using UnityEngine;
using UnityEngine.Tilemaps;

public class ExampleClass : MonoBehaviour { void Start() { Tilemap tilemap = transform.parent.GetComponent<Tilemap>(); Vector3Int cellPosition = tilemap.LocalToCell(transform.localPosition); transform.localPosition = tilemap.GetCellCenterLocal(cellPosition); } }