- Home /
Terrain Disappears on Mouseclicks :(
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);
}
}
}
}
Answer by Paulo-Henrique025 · Jul 18, 2014 at 10:37 AM
Are you moving the entire terrain to the hit position?
transform.position = hit.point;
Make sure the terrain is not just being moved to another point of the world.
Answer by Saeedk78 · Jul 18, 2014 at 11:20 AM
Check your terrain that has any script. i guess when you click on the scene your terrain moves.
Your answer
Follow this Question
Related Questions
Monodevelop message error 0 Answers
How to fix code errors? 1 Answer
MonoDevelop 4 - EU Keyboard and Themes 0 Answers
No custom scripts will work.*Using US.* 1 Answer
Placing 3d model onmouseclick 0 Answers