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…

Yeah I know its because of that.. I made the cube in planes so I have to figure out how to put on plane on the other plane.
– jmgekI assume that you have all six planes as children of an empty game object. If so add a new empgy game object as the parent of the current plane paren. Then adjust the position of the child. If all six planes were created in max (rather than the cube being build in Unity out of planes authored in max), then you can go back to max and reset the origin as well.
– robertbu