using UnityEngine;
using System.Collections;
public class ConstructionSpacestation : 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))
{
float dot = Vector3.Dot(transform.up, hit.normal);
if (dot > 1)
{
Debug.Log("yes");
}
// it's better to find the center of the face like this:
Vector3 position = hit.transform.position + hit.normal * 0.5f;
// calculate the rotation to create the object aligned with the face normal:
Quaternion rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
// create the object at the face center, and perpendicular to it:
GameObject Placement = Instantiate(Builder, position, rotation) as GameObject;
Debug.Log(hit.collider.gameObject.name);
}
else
{
Debug.Log(hit.collider.gameObject.name);
}
}
}
}
I am trying to make this script that instantiates a cube on another cube ‘minecraft style’ make it so I cant instantiate on specific sides. If you could explain how vector3.dot(Transform.up) works I might understand it, as it is there is not a lot of documentation on it.
Thanks in advance.