using UnityEngine;
using System.Collections;
public class ConstructionSpacestation : MonoBehaviour
{
public GameObject Builder;
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;
Debug.Log(actualBlock);
actualBlock.position = hit.point + hit.normal * 0.5f;
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.position, Quaternion.identity) as GameObject;
}
else
{
Debug.Log("nothing");
}
}
}
}
I hacked together this script to instantiate a cube right next to another. But it is spitting them out at odd places, and also deleating cubes from behind.
Can you explain what Is going on? is it the hit.point that is screwing up?!