So ive made a grid out of cubes with two seperate scripts attached to it. One to highlight the cube by changing its color, the other is a raycast 1.0 high going up. what im wondering is how to i make a non rigid body cube spawn at the top of the point of the raycast.
code for Raycast:
using UnityEngine;
using System.Collections;
public class CubeRaycast : MonoBehaviour {
public RaycastHit hit;
public GameObject Cube;
public float range = 1.0F;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 DirectionRay = transform.TransformDirection(Vector3.up);
Debug.DrawRay(transform.position, DirectionRay * range, Color.red);
if (Physics.Raycast(transform.position, transform.up, out hit, 1F))
{
if(Input.GetKeyDown(KeyCode.Mouse0)){
range += 1.0F;
GameObject instanceCube = Instantiate(Cube,hit.point,transform.rotation)as GameObject;
}
}
}
}