• PlaceTargetWithMouse.cs
  • /
  • /
  • /
  • /
1 using System;
2 using
UnityEngine;
3
4
5 namespace
UnityStandardAssets.SceneUtils
6 {
7     
public class PlaceTargetWithMouse : MonoBehaviour
8     {
9         
public float surfaceOffset = 1.5f;
10         
public GameObject setTargetOn;
11
12         
// Update is called once per frame
13         
private void Update()
14         {
15             
if (!Input.GetMouseButtonDown(0))
16             {
17                 
return;
18             }
19             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
20             RaycastHit hit;
21             
if (!Physics.Raycast(ray, out hit))
22             {
23                 
return;
24             }
25             transform.position = hit.point + hit.normal*surfaceOffset;
26             
if (setTargetOn != null)
27             {
28                 setTargetOn.SendMessage(
"SetTarget", transform);
29             }
30         }
31     }
32 }


Gõ tìm kiếm nhanh...