Version: 2022.3
言語: 日本語
public Vector3Int WorldToCell (Vector3 worldPosition);

パラメーター

worldPosition World Position to convert.

戻り値

Vector3Int Cell position of the world position.

説明

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); } }