Version: 2021.3
언어: 한국어

Grid.GetCellCenterLocal

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

파라미터

position Grid 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. This is mathematically correct, but when for example instantiating a GameObject into the grid, you often prefer the center of the cell instead.

// Snap the GameObject to parent Grid center of cell
using UnityEngine;

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