Advertisement
duck

Unity 3D picking target position on terrain with mouse c#

Aug 22nd, 2011
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.41 KB | None | 0 0
  1. // Unity 3D example picking a target position on a terrain using the mouse cursor using ray casting
  2.  
  3. using UnityEngine;
  4. using System.Collections;
  5.  
  6. public class MouseTarget : MonoBehaviour {
  7.    
  8.     void Update ()
  9.     {
  10.         Ray ray = camera.ScreenPointToRay(Input.mousePosition);
  11.         RaycastHit hit;
  12.         if(Terrain.active.collider.Raycast(ray,out hit,Mathf.Infinity))
  13.         {  
  14.             transform.position = hit.point 
  15.         }
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement