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?!
Yeah I did the exact same thing that you just posted 'I just called the transform var newbloc'. I dont understand how I can move a prefab when its already instantiated. I really appreciated your answers.
– jmgekI tried doing what you said... Its not working out for me.. I am trying to convert js to c# and I can get the placement right but then it does this.
– jmgek