Hi,
i am able to make up-to below code where i am trying to get co-ordinates(X,Y) on the terrain on mouse-click, apparently i succeeded.
i am able to print coordinates but upon mouse-click
Terrain disappears suddenly and model
falls from where it is.
Attaching screen shot for your reference.
Please suggest where i am doing wrong, Here comes my complete script.
using UnityEngine;
using System.Collections;
using UnityEditor;
public class TerrainEdit : MonoBehaviour
{
// Use this for initialization
public void Start ()
{
}
// Update is called once per frame
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit))
{
transform.position = hit.point;
print("First Click: " + transform.position.x + " , " + transform.position.y);
}
}
if(Input.GetMouseButtonDown(1))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit))
{
transform.position = hit.point;
print("Second Click: " + transform.position.x + " , " + transform.position.y);
}
}
}
}
[29369-before+mouse+click2.png|29369]
[29370-after+mouse+click.png|29370]