private void Interact() { if (input.interactRequest == true) { CellData interactCell = GridData.GetCellAt(Coordinates.FromWorldSpace(input.interactPosition)); if (interactCell != null) { ExtensibleData extensible = null; if (interactCell.obstacle != null) { extensible = interactCell.obstacle; } else if (interactCell.item != null) { extensible = interactCell.item; } else if (interactCell.entity != null) { extensible = interactCell.entity; } if (extensible != null) { InteractableData interactable = (InteractableData)extensible.GetExtension(PStrings.interactable); if (interactable != null) { float sqrDistanceThreshold = 2.0f; Vector3 interactablePosition = new Vector3(extensible.gameObject.transform.position.x, 0, extensible.gameObject.transform.position.z); Vector3 interactorPosition = new Vector3(rigidbody.position.x, 0, rigidbody.position.z); if ((interactablePosition - interactorPosition).sqrMagnitude <= (sqrDistanceThreshold * sqrDistanceThreshold)) { interactable.Switch(); } } } } } }