I create an emtpy game object and attach .cs file. I try to load a prefab(.obj file) on mouse click position. My code is :
Ray ray;
RaycastHit hit;
public GameObject prefab;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
ray=Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
GameObject obj = Instantiate(prefab, new Vector3(hit.point.x, hit.point.y, hit.point.z), Quaternion.identity) as GameObject;
}
else
{
Debug.Log("Physics.Raycast returns false");
}
}
Raycast returns false everytime.