I have a building mechanism that allows you to place blocks, it’s all free and custom, though i want it to be in a grid, so when you place it, it’ll be exactly the same to the grid.
i didn’t try anything yet, but this is the script i’ve been using to place blocks:
using UnityEngine;
using System.Collections;
public class PlaceBlock : MonoBehaviour
{
Ray ray;
RaycastHit hit;
public GameObject prefab;
public GameObject prefab2;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (Input.GetKeyDown(KeyCode.X))
{
GameObject obj = Instantiate(prefab, new Vector3(hit.point.x, hit.point.y + 0.5f, hit.point.z), Quaternion.identity) as GameObject;
}
if (Input.GetKeyDown(KeyCode.Z))
{
GameObject obj = Instantiate(prefab2, new Vector3(hit.point.x, hit.point.y + 0.5f, hit.point.z), Quaternion.identity) as GameObject;
}
}
}
}
i have no idea how to acomplish it, i need help
this is how it looks so far