Hi I m new to unity C# coding i had taken help of Leap Motion tutorial to move the camera in and out according to the hand gesture but it is giving me
ArgumentOutOfRangeException : Argument is out of range.
Parameter name: index
code is below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Leap;
using Leap.Unity;
public class ControlMove : MonoBehaviour {
Controller controller;
float HandPalmPitch;
float HandPalmYam;
float HandPalmRoll;
float HandWristRot;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
controller = new Controller ();
Frame frame = controller.Frame ();
List hands = frame.Hands;
if (frame.Hands.Count > 0) {
Hand fristhand = hands [0];
}
HandPalmPitch = hands [0].PalmNormal.Pitch;
HandPalmRoll = hands [0].PalmNormal.Roll;
HandPalmYam = hands [0].PalmNormal.Yaw;
HandWristRot = hands [0].WristPosition.Pitch;
Debug.Log (“Pitch :” + HandPalmPitch);
Debug.Log (“Roll :” + HandPalmRoll);
Debug.Log (“Yam :” + HandPalmYam);
//Move Object
if (HandPalmYam > -2f && HandPalmYam < 3.5f) {
transform.Translate (new Vector3 (0, 0, 1 * Time.deltaTime));
} else if (HandPalmYam < -2.2f) {
transform.Translate (new Vector3 (0, 0, -1 * Time.deltaTime));
}
}
}
Use Code Tags as described in this post , which is stickied at the top of every forum here.
Do not create multiple threads for the same problem.
mayank_chaurasia:
Hi I m new to unity C# coding i had taken help of Leap Motion tutorial to move the camera in and out according to the hand gesture but it is giving me
ArgumentOutOfRangeException : Argument is out of range.
Parameter name: index
code is below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Leap;
using Leap.Unity;
public class ControlMove : MonoBehaviour {
Controller controller;
float HandPalmPitch;
float HandPalmYam;
float HandPalmRoll;
float HandWristRot;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
controller = new Controller ();
Frame frame = controller.Frame ();
List hands = frame.Hands;
if (frame.Hands.Count > 0) {
Hand fristhand = hands [0];
}
HandPalmPitch = hands [0].PalmNormal.Pitch;
HandPalmRoll = hands [0].PalmNormal.Roll;
HandPalmYam = hands [0].PalmNormal.Yaw;
HandWristRot = hands [0].WristPosition.Pitch;
Debug.Log (“Pitch :” + HandPalmPitch);
Debug.Log (“Roll :” + HandPalmRoll);
Debug.Log (“Yam :” + HandPalmYam);
//Move Object
if (HandPalmYam > -2f && HandPalmYam < 3.5f) {
transform.Translate (new Vector3 (0, 0, 1 * Time.deltaTime));
} else if (HandPalmYam < -2.2f) {
transform.Translate (new Vector3 (0, 0, -1 * Time.deltaTime));
}
}
}
id you get the fix for this ?
There is a ‘fix’ in the linked thread. Your code is probably different. In the future, please lookup errors and/or post your own thread if you have an issue.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Leap;
using Leap.Unity;
public class iliketomoveit : MonoBehaviour {
Controller controller;
float HandPalmPitch;
float HandPalmYam;
float HandPalmRoll;
float HandWristRot;
void Start () {
}
// Update is called once per frame
void Update () {
controller = new Controller();
Frame frame = controller.Frame();
List hands = frame.Hands;
if (frame.Hands.Count > 0)
{
Hand fristHand = hands[0];
}
HandPalmPitch = hands[0].PalmNormal.Pitch;
HandPalmRoll = hands[0].PalmNormal.Roll;
HandPalmYam = hands[0].PalmNormal.Yaw;
HandWristRot = hands[0].WristPosition.Pitch;
Debug.Log(“Pitch :” + HandPalmPitch);
Debug.Log(“Roll :” + HandPalmRoll);
Debug.Log(“Yam :” + HandPalmYam);
if (HandPalmYam > -2f && HandPalmYam < 3.5f)
{
transform.Translate ( new Vector3(0, 0,1 * Time.deltaTime));
}else if (HandPalmYam < -2.2f)
{
transform.Translate ( new Vector3(0, 0, -1 * Time.deltaTime));
}
}
}
this is the code and the image is the error . can you give me the updated code with the ‘fix’ ?
nilsdr
March 16, 2018, 9:26am
6
Your frame.Hands is empty, therefor there is no item at index 0.