Version: 2017.3
public Vector3Int WorldToCell (Vector3 worldPosition);

Parámetros

worldPosition World Position to convert.

Valor de retorno

Vector3Int Cell position of the world position.

Descripción

Converts a world position to cell position.

// Snap the GameObject to parent GridLayout
using UnityEngine;

public class ExampleClass : MonoBehaviour { void Start() { GridLayout gridLayout = transform.parent.GetComponentInParent<GridLayout>(); Vector3Int cellPosition = gridLayout.WorldToCell(transform.position); transform.position = gridLayout.CellToWorld(cellPosition); } }