Cube instantiate problem.

Hey guys, I am trying to make a box placement kind of like minecraft to build objects.
I have my cubes made up of 6 planes because I will need to check diffrent sides for being hit and exploding.

using UnityEngine;
using System.Collections;

public class ConstructionSpacestation : MonoBehaviour
{

    public GameObject SetObject;

    void Start()
    {

    }

    void Update()
    {

        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 2000))
            {
               

                Transform clickedObj = hit.transform;
                Debug.Log(clickedObj);

                GameObject close = Instantiate(SetObject, Vector3.zero, Quaternion.identity) as GameObject;
                close.transform.position = hit.transform.position + hit.normal; 

           
            }
            else
            {
                Debug.Log("nothing");
            }
        }

    }
}

It places the objects but I have no idea why its doing this.

No matter what I do I cant get the boxes to instancing uniformly beside each other either from the top or the side or any other place I raycast hit they move over what ever way.

I tried this with making a instance with a 1,1,1 cube and it works!

I just cant get it to work with the object prefabs I make in max…

Seems to me that you place the cubes at the exact location of the raycast hits. What you want to do is to place them on some kind of uniform grid. For example, if your cubes were of side length 1, you could just round the hit coords to full integer values on a given plane. :slight_smile: