I am currently try to cast the ray from the Leap Motion hand to control player’s movement, and then I found this codelink text
but when I paste in my project, it keeps give me NullReferenceException
“NullReferenceException: Object reference not set to an instance of an object
HandRaycast.Start () (at Assets/Script/HandRaycast.cs:25)”
Here is the code
using Leap;
using Leap.Unity;
using System.Collections.Generic;
using UnityEngine;
public class HandRaycast : MonoBehaviour {
Hand leapHand;
FingerModel finger;
HandModel handModel;
// Use this for initialization
void Start()
{
/*Controller controller = new Controller();
Frame frame = controller.Frame(); // controller is a Controller object
if (frame.Hands.Count > 0)
{
List<Hand> hands = frame.Hands;
leapHand = hands[0];
}
finger = leapHand.Fingers;
Finger.FingerType fingerType = finger.Type;*/
handModel = GetComponent<HandModel>();
leapHand = handModel.GetLeapHand();
if (leapHand == null) Debug.LogError("No leap_hand founded");
}
// Update is called once per frame
void Update () {
Vector3 fwd = transform.TransformDirection(Vector3.forward);
RaycastHit hit;
for (int i = 0; i < HandModel.NUM_FINGERS; i++)
{
finger = handModel.fingers*;*
if (Physics.Raycast(finger.GetTipPosition(), fwd, out hit))
{
float distanceToGround = hit.distance;
Debug.Log(“hit something” + distanceToGround);
}
Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red, Time.deltaTime, true);
}
}
}
Do any one know the solution?
Moreover, do anyone know how to scale OSVR VRFirstPersonController without canvas position affected? Everytime I adjust VRFirstPersonController scale, I do not know why the canvas on VREye1 always disappear.