using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using Leap;
using Leap.Unity;

// PlanA 	cube
//PlanB plamnormal



public class beam : MonoBehaviour {

	private LeapProvider mProvider;
	Frame mFrame;
	Hand mHand;

	public float thickness = 0.002f;
	public float thicknessIn = 0.008f;
	public GameObject pointer;

	private LineRenderer line; 
	private int i = 0;  

	Vector3 RunStart = Vector3.zero;
	Vector3 RunNext = Vector3.zero;

	bool isNUll = true;

	//beam pos and direction
	Vector3 pos = Vector3.zero;
	Vector3 dir = Vector3.zero;

	//finger tip
	GameObject tip;
	GameObject move;


	// Use this for initialization
	void Start () {
		mProvider = FindObjectOfType<LeapProvider> () as LeapProvider;



		pointer = GameObject.CreatePrimitive(PrimitiveType.Cube);
		pointer.transform.parent = this.transform;
		pointer.transform.localScale = new Vector3(0.000f, 0.000f, 10.0f);
		pointer.transform.position = this.transform.position;
		pointer.transform.rotation = this.transform.rotation;


		 tip = GameObject.Find("tip");

	
	}
	
	// Update is called once per frame
	void Update () {


		mFrame = mProvider.CurrentFixedFrame;
		int numHands = mFrame.Hands.Count;

		if (numHands >0) {

			if (numHands == 1) {


				foreach (var itemFingers in mFrame.Hands) {
					int numF =	itemFingers.Fingers.Count;

					float dis =	itemFingers.PinchDistance;
					float disN = itemFingers.PinchStrength;


				

					if (dis < 50.0f || disN > 0.4f) {
						pointer.transform.localScale = new Vector3 (0.000f, 0.000f, 10.0f);



					} else {

						pointer.transform.localScale = new Vector3(0.0008f, 0.0008f, 10.0f);

						Ray ray = new Ray (transform.position, -transform.forward);
						//var point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
						Debug.DrawLine(transform.position, -transform.forward*100,Color.red);  //这个就是绘制出的射线了,包含发射位置,发射距离和射线的颜色; 

						RaycastHit hit;

						if (Physics.Raycast (ray, out hit, 100)) { 
							//print ("hello");
							print (hit.point);
							//hit.point;
							tip.transform.position = hit.point;


						}





					}
				
					//print (numF);
					//itemFingers.PalmNormal
				}
				//print ("Find one hand");
				//pointer.transform.position.z = pointer.transform.position.z + 1.0f;
			}

			if (numHands == 2) {

				//print ("Find two hands");

			}
		}
			
	}
}


注意事项:把手上各关节的collider都去掉。不然计算的碰撞点位置不对。

Leap的Scene窗口中在手心发射线,Game窗口中也可见,并将碰撞点用小球表示_知识

Leap的Scene窗口中在手心发射线,Game窗口中也可见,并将碰撞点用小球表示_ide_02