Kartik_Khangar_26
using UnityEngine; public class PlayerController : MonoBehaviour { public GameObject blockPrefab; public float reachDistance = 5f; void Update() { if (Input.GetMouseButtonDown(0)) // Left click to break block { BreakBlock(); } if (Input.GetMouseButtonDown(1)) // Right click to place block { PlaceBlock(); } } void BreakBlock() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, reachDistance)) { Destroy(hit.transform.gameObject); } } void PlaceBlock() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, reachDistance)) { Vector3 placePosition = hit.point + hit.normal * 0.5f; Instantiate(blockPrefab, placePosition, Quaternion.identity); } } }
