-
-
Save ircnelson/ed2092b5ec94ff78c6001c5e0e8d05a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class CubePlacer : MonoBehaviour | |
{ | |
private Grid grid; | |
private void Awake() | |
{ | |
grid = FindObjectOfType<Grid>(); | |
} | |
private void Update() | |
{ | |
if (Input.GetMouseButtonDown(0)) | |
{ | |
RaycastHit hitInfo; | |
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
if (Physics.Raycast(ray, out hitInfo)) | |
{ | |
PlaceCubeNear(hitInfo.point); | |
} | |
} | |
} | |
private void PlaceCubeNear(Vector3 clickPoint) | |
{ | |
var finalPosition = grid.GetNearestPointOnGrid(clickPoint); | |
GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = finalPosition; | |
//GameObject.CreatePrimitive(PrimitiveType.Sphere).transform.position = nearPoint; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment