using UnityEngine;
public class BlockPlace : MonoBehaviour
{
public GameObject blockPrefab;
public Camera playerCamera;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = playerCamera.ScreenPointToRay(
new Vector3(Screen.width / 2, Screen.height / 2));
if (Physics.Raycast(ray, out RaycastHit hit, 5f))
{
Vector3 pos = hit.point + hit.normal * 0.5f;
pos = new Vector3(
Mathf.Round(pos.x),
Mathf.Round(pos.y),
Mathf.Round(pos.z));
Instantiate(blockPrefab, pos, Quaternion.identity);
}
}
}
}1 views