using UnityEngine;
using System.Collections;
public class construc : MonoBehaviour
{
public GameObject Builder;
// placeholder for what you see on the screen.
private Transform actualBlock;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 2000))
{
Transform actualBlock = hit.transform;
actualBlock.position = hit.point + hit.normal * 1f;
actualBlock.transform.position = new Vector3(
Mathf.Round(actualBlock.position.x),
Mathf.Round(actualBlock.position.y),
Mathf.Round(actualBlock.position.z)
);
GameObject Placement = Instantiate(Builder, actualBlock.transform.position, Quaternion.identity) as GameObject;
}
else
{
Debug.Log("nothing");
}
}
}
}
I am trying to get this script to Instantiate a cube on to another one from its face, minecraft style.
But what it is doing is also moving the cube that I clicked on. why is it doing that.
I understand I am not making a new transform for actual block but I have no idea how to script how to do it. please help.