Objects that I am instantiating into my game are being placed above the level of my terrain (not always the same height but about 6 - 7 units higher)
This is my script-
using UnityEngine;
using System.Collections;
public class ObjectToFollowMouse : MonoBehaviour
{
public GameObject Target;
public GameObject ActualPrefab;
RaycastHit hit;
private float raycastLength = 1000;
void Start()
{
}
void Update()
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
//Makes the 'Fake' Prefab follow the mouse.
if(Physics.Raycast(ray, out hit, raycastLength))
{
Debug.Log(hit.collider.name);
if(hit.collider.name == "Terrain")
{
Target.transform.position = hit.point;
}
}
//Instantiates Actual Building Prefab
if(Input.GetMouseButtonDown(1))
{
GameObject TargetObj = Instantiate(ActualPrefab, hit.point, Quaternion.identity) as GameObject;
TargetObj.name = "Target Instantiated";
//Destroys the Fake !
Destroy(gameObject);
}
}
}
How can I ensure the units/objects are always going instantiate at ground level.
???