Question by
silviufuicu · Sep 07, 2016 at 02:33 PM ·
c#movementterrainclickmouseclick
Move only if mouse click the Terrain
I want to move the player only if mouse click on Terrain, any idea?
// Moves the Player if the Left Mouse Button was clicked
if (Input.GetMouseButtonDown (0) && GUIUtility.hotControl == 0) {
Plane playerPlane = new Plane (Vector3.up, myTransform.position);
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
float hitdist = 0.0f;
if (playerPlane.Raycast (ray, out hitdist)) {
Vector3 targetPoint = ray.GetPoint (hitdist);
destinationPosition = ray.GetPoint (hitdist);
Comment
Change the layer of your Terrain and change the raycast function:
if (Physics.Raycast(ray, out hit, $$anonymous$$athf.Infinity /*distance*/,Layer$$anonymous$$ask.get$$anonymous$$ask("Name of terrain layer")))