Version: 2019.1
public Vector3Int LocalToCell (Vector3 localPosition);

Parameters

localPositionLocal Position to convert.

Returns

Vector3Int Cell position of the local position.

Description

Converts a local position to cell position.

// Snap the GameObject to parent GridLayout
using UnityEngine;

public class ExampleClass : MonoBehaviour { void Start() { GridLayout gridLayout = transform.parent.GetComponent<GridLayout>(); Vector3Int cellPosition = gridLayout.LocalToCell(transform.localPosition); transform.localPosition = gridLayout.CellToLocal(cellPosition); } }